本文主要是介绍uva 567,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Floyd 算法 就输入麻烦点
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define INF 100
using namespace std;
int a[21][21];int main()
{int n, ca = 1;while(scanf("%d", &n) != EOF){for(int i = 1; i <= 20; i++)for(int j = 1; j <= 20; j++){if(i == j)a[i][j] = 0;elsea[i][j] = INF;}for(int j = 0; j < n; j++){int x;scanf("%d", &x);a[1][x] = a[x][1] = 1;}for(int i = 2; i < 20; i++){scanf("%d", &n);for(int j = 0; j < n; j++){int x;scanf("%d", &x);a[i][x] = a[x][i] = 1;}}for(int k = 1; k <= 20; k++)for(int i = 1; i <= 20; i++)for(int j = 1; j <= 20; j++)a[i][j] = min(a[i][j], a[i][k] + a[k][j]);scanf("%d", &n);printf("Test Set #%d\n", ca++);for(int i = 0; i < n; i++){int x,y;scanf("%d%d", &x, &y);printf( "%2d to %2d: %d\n", x, y, a[x][y]);}puts("");}return 0;
}
这篇关于uva 567的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!