| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
深搜水过 132K 16MS#include<cstdio>
using namespace std;
int e[101][101],b,ans=2000000000;
bool vis[101];
void dfs(int v,int step)
{
if(step>=ans)return;
if(v==b)
{
ans=step;
return;
}
vis[v]=true;
if(e[v][0]&&vis[e[v][1]]==false)dfs(e[v][1],step);
for(int i=2;i<=e[v][0];i++)
if(vis[e[v][i]]==false)dfs(e[v][i],step+1);
vis[v]=false;
}
int main()
{
int n,a,i,j;
scanf("%d%d%d",&n,&a,&b);
for(i=1;i<=n;i++)
{
scanf("%d",&e[i][0]);
for(j=1;j<=e[i][0];j++)scanf("%d",&e[i][j]);
}
dfs(a,0);
if(ans==2000000000)printf("-1\n");
else printf("%d\n",ans);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator