#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<queue> #include<vector> using namespace std; int main() { //freopen("input.txt","r",stdin); int i,j,k,l,m,n,y=1; while(scanf("%d",&n)==1) { vector<int>country[1000]; for(i=1;i<=n;i++) { scanf("%d",&m); country[1].push_back(m); country[m].push_back(1); } for(i=2;i<20;i++) { scanf("%d",&n); for(j=1;j<=n;j++) { scanf("%d",&m); country[i].push_back(m); country[m].push_back(i); } } int n; scanf("%d",&n); printf("Test Set #%d\n",y++); while(n--) { int source,destination,d[21],color[21]; scanf("%d %d",&source,&destination); for(i=1;i<=20;i++) { color[i]=0; } queue<int>q; q.push(source); while(!q.empty()) { int u=q.front(); q.pop(); if(u==destination)break; for(i=0;i<country[u].size();i++) { int v=country[u][i]; if(color[v]==0) { q.push(v); color[v]=color[u]+1; } } } printf("%2d to %2d: %d\n",source,destination,color[destination]); } printf("\n"); } return 0;
Monday, August 25, 2014
uva : 567 - Risk
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment