Carefully read the question, found: The edge of the weight value is set to 1, then converted to two points between the shortest path problem ... One excited, with the Dijkstra, and the document ended. =eof forgot to write, TLE ... Then use Floyd, smooth AC ...
#include <stdio.h>
#include <string.h>
int w[21][21];
int main ()
{
int i,j,t,u,n,ncase=1;
while (scanf ("%d", &t)!=eof)
{for
(i=1;i<=20;i++)
{for
(j=1;j<=20;j++)
w[i][j]= ;
w[i][i]=0;
}
for (j=0;j<t;j++)
{
scanf ("%d", &u);
w[1][u]=w[u][1]=1;
}
for (i=2;i<=19;i++)
{
scanf ("%d", &t);
for (j=0;j<t;j++)
{
scanf ("%d", &u);
w[i][u]=w[u][i]=1;
}
}
for (int. k=1;k<=20;k++) for
(i=1;i<=20;i++) for
(j=1;j<=20;j++)
if (W[i][j]>w[i][k]+w[k] [j])
W[I][J]=W[I][K]+W[K][J];
scanf ("%d", &n);
printf ("Test Set #%d\n", ncase++);
for (i=0;i<n;i++)
{
scanf ("%d%d", &t,&u);
printf ("%d to%d:%d\n", T,u,w[t][u]);
}
printf ("\ n");
}
return 0;
}