标签: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;
}
标签:cst min string type tor getch return for clu
原文地址:http://www.cnblogs.com/codetogether/p/7608009.html