//看懂题目之后发现很水,最短路,数据小,直接flyod.
1 Source Code
2
3 Problem: 1847 User: eth1
4 Memory: 292K Time: 32MS
5 Language: C++ Result: Accepted
6 Source Code
7 #include <iostream>
8 #include <cstring>
9 #include <algorithm>
10  using namespace std;
11 #define maxx 1000000
12 int map[105][105];
13 int main()
14 {
15 int a,b,c,n,m;
16 cin>>a>>b>>c;
17 //memset(map,-1,sizeof(map));
18 for(int i=1;i<=a;i++)
19 for(int j=1;j<=a;j++)
20 map[i][j] = maxx;
21 for(int i=1;i<=a;i++)
22 {
23 cin>>n;
24 for(int j=0;j<n;j++)
25 {
26 cin>>m;
27 if(j==0) map[i][m]=0;
28 else map[i][m]=1;
29 }
30 }
31 for(int k=1;k<=a;k++)
32 for(int i=1;i<=a;i++)
33 for(int j=1;j<=a;j++)
34 {
35 if(map[i][k]+map[k][j] < map[i][j]) map[i][j] = map[i][k]+map[k][j];
36 }
37 if(map[b][c] == maxx) cout<<-1<<endl;
38 else cout<<map[b][c]<<endl;
39 return 0;
40 }

 posted on 2011-05-09 18:23  eth0  阅读(135)  评论(0编辑  收藏  举报