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 |
同学们,这个有必要用什么RMQ,LCA不?就一个询问哎~2个10000的数组就可以# 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator