码迷,mamicode.com
首页 > 其他好文 > 详细

luogu_1613 跑路

时间:2017-09-28 19:16:39      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:cst   min   string   type   tor   getch   return   for   clu   

#include <cstdio>
#include <iostream>
#include <queue>
#include <cctype>
#include <vector>
#include <cstring>
using namespace std;
int n,m,d[70][70];
bool G[70][70][70];

int read(){
    char c; int x=0;
    c=getchar();
    while(c<48){
        c=getchar();
    }
    while(c>=48){
        x=x*10+c-‘0‘;
        c=getchar();
    }
    return x;
}

int main(){
    memset(d,10,sizeof(d));
    n=read(); m=read();
    while(m--){
        int u,v; 
		u=read(); v=read();
        d[u][v]=1;
        G[u][v][0]=true;
    }
    for(int k=1;k<=64;k++)
    	for(int i=1;i<=n;i++)
    		for(int j=1;j<=n;j++)
    			for(int l=1;l<=n;l++)
    				if(G[i][j][k-1] && G[j][l][k-1]){
    					G[i][l][k]=true;
    					d[i][l]=1;
					}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	printf("%d\n",d[1][n]);
    return 0;
}

  

luogu_1613 跑路

标签:cst   min   string   type   tor   getch   return   for   clu   

原文地址:http://www.cnblogs.com/codetogether/p/7608009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!