| ||||||||||
| 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 | |||||||||
我这样子做了变成了超时你觉得有可能吗?#include <stdio.h>
#include <string.h>
#define size 10010
int father[size];
int vis[size];
int main()
{
int cases,i,n,f,s,x,y,a,b;
scanf("%d",&cases);
while(cases--)
{
scanf("%d",&n);
memset(father,-1,sizeof(father));
memset(vis,0,sizeof(vis));
for(i=1;i<n;i++)
{
scanf("%d %d",&f,&s);
father[s]=f;
}
scanf("%d %d",&x,&y);
while(father[x]!=-1)
{
vis[x]=1;
x=father[x];
}
while(!vis[y])
{
y=father[y];
}
printf("%d\n",y);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator