zoj 1221 || poj 1603 Risk(Floyd~)

终于瞅见一道最短路的题了~~~哈哈~~

 

这个题目好长啊,好长啊。。。

 

挺不容易的 读完题。。。其实没仔细读,基本看了看样例输入输出还有那个图就知道啦~~呵呵

 

就是求两点中间的最少的城市个数,That's all.

 

#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> using namespace std; int main(void) { int map[25][25]; int count = 1,from,to,n; while( scanf("%d",&n)!= EOF ) { for(int i=1; i<=20; i++) for(int k=1; k<=20; k++) map[i][k] = 10000; while( n-- ) { scanf("%d",&to); map[1][to] = map[to][1] = 1; } for(int i=2; i<=19; i++) { scanf("%d",&n); while( n-- ) { scanf("%d",&to); map[i][to] = map[to][i] = 1; } } for(int i=1; i<=20; i++) //Floyd~~~~ for(int k=1; k<=20; k++) for(int j=1; j<=20; j++) if( map[k][j] > map[k][i] + map[i][j] ) map[k][j] = map[k][i] + map[i][j]; scanf("%d",&n); printf("Test Set #%d/n",count++); while( n-- ) { scanf("%d %d",&from,&to); printf("%d to %d: %d/n",from,to,map[from][to]); } printf("/n"); // Don't forget this, = =...PE.. } return 0; }  

你可能感兴趣的:(zoj 1221 || poj 1603 Risk(Floyd~))