Posted on 2008-05-03 22:59
superman 阅读(188)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1221 C++ 00:00.00 840K */
2 #include <iostream>
3
4 using namespace std;
5
6 int main()
7 {
8 int Test = 0;
9 while(true)
10 {
11 unsigned map[21][21];
12 memset(map, 255, sizeof(map));
13
14 for(int s = 1; s < 20; s++)
15 {
16 int n, t;
17 if(cin >> n == false)
18 return 0;
19 while(n--)
20 {
21 cin >> t;
22 map[s][t] = map[t][s] = 1;
23 }
24 }
25
26 for(int k = 1; k <= 20; k++)
27 for(int i = 1; i <= 20; i++)
28 for(int j = 1; j <= 20; j++)
29 if(map[i][k] != UINT_MAX && map[k][j] != UINT_MAX)
30 map[i][j] <?= (map[i][k] + map[j][k]);
31
32 int n, s, t; cin >> n;
33
34 cout << "Test Set #" << ++Test << endl;
35 while(n--)
36 {
37 cin >> s >> t;
38 cout << s << " to " << t << ": " << map[s][t] << endl;
39 }
40 cout << endl;
41 }
42
43 return 0;
44 }
45