#include <stdio.h>
[bo]typedef[/bo] [bo]struct[/bo] _node{
[bo]int[/bo] value;
[bo]struct[/bo] _node* pNext;
}node;
[bo]const[/bo] [bo]int[/bo] MAX_EDGE = 20001;
[bo]const[/bo] [bo]int[/bo] MAX_CITY = 10001;
node nd_pool[MAX_EDGE*2];
[bo]int[/bo] nPoolIndex;
[bo]int[/bo] main()
{
[bo]int[/bo] n,k;
[bo]int[/bo] a,b;
[bo]int[/bo] p,q;
[bo]while[/bo](scanf("%d%d", &n, &k), n)
{
[bo]int[/bo] nCount[MAX_CITY] = {0};
[bo]int[/bo] nUse[MAX_CITY] = {0};
node nd[MAX_CITY] = {0};
node* ndQueue[MAX_EDGE] = {0};
[bo]int[/bo] QueueBeg=0, QueueEnd=0;
nPoolIndex = 0;
[bo]for[/bo]([bo]int[/bo] n1=0; n1<k; ++n1)
{
node *pt;
scanf("%d%d", &a, &b);
{
pt = nd[a].pNext;
nd[a].pNext=nd_pool + nPoolIndex++;
nd[a].pNext->value=b;
nd[a].pNext->pNext=pt;
}
{
pt = nd[b].pNext;
nd[b].pNext=nd_pool + nPoolIndex++;
nd[b].pNext->value=a;
nd[b].pNext->pNext=pt;
}
}
scanf("%d%d", &p, &q);
nUse[p] = 1;
ndQueue[QueueBeg++] = &nd[p];
nCount[p]=1;
[bo]int[/bo] nCur = 1;
[bo]for[/bo](;QueueEnd<QueueBeg && QueueBeg<=k;) //BFS队列
{
[bo]for[/bo]([bo]int[/bo] nB=QueueBeg; QueueEnd<nB; ++QueueEnd) //搜索当前层
{
[bo]for[/bo](node* pn=ndQueue[QueueEnd]->pNext; pn; pn = pn->pNext) //搜索所有子结点
{ [bo]if[/bo](nUse[pn->value]==0)
{
nUse[pn->value] = 1;
ndQueue[QueueBeg] = &nd[pn->value]; //加到队列尾
[bo]if[/bo](nCount[pn->value]==0)
{
nCount[pn->value] = nCur+1;// nCount[nCur] + 1;
}
++QueueBeg;
}
}
}
nCur++;// = ndQueue[QueueEnd]->pNext->value;
}
[bo]if[/bo](nCount[q]==0)
puts("No solution");
[bo]else[/bo] [bo]if[/bo](nCount[q]==1)
puts("0");
[bo]else[/bo]
printf("%d\n", nCount[q]-2);
}
[bo]return[/bo] 0;
}
My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.