Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我这样子做了变成了超时你觉得有可能吗?

Posted by chenxuan123456789 at 2012-08-19 15:16:37 on Problem 1330
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator