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

同学们,这个有必要用什么RMQ,LCA不?就一个询问哎~2个10000的数组就可以

Posted by yzhw at 2010-08-05 15:57:35 on Problem 1330
# include <cstdio>
using namespace std;
const int N=10001;
int main()
{
    int testcase;
    scanf("%d",&testcase);
    while(testcase--)
    {
          bool path[N];
          int pre[N];
          int n;
          scanf("%d",&n);
          for(int i=0;i<=n;i++)
             pre[i]=0,path[i]=0;
          for(int i=1;i<n;i++)
          {
             int t1,t2;
             scanf("%d %d",&t1,&t2);
             pre[t2]=t1;
          }
          int s,e;
          scanf("%d %d",&s,&e);
          while(s!=0)
          {
            path[s]=1;
            s=pre[s];
          }
          while(e!=0)
          {
            if(path[e])
               {
                  printf("%d\n",e);
                  break;
               }
            e=pre[e];
          }
    }
    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