1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #include<bits/stdc++.h> using namespace std; #define ll long long const int maxn = 5e4+10; int fa[maxn]; struct node { int job; int time; node(){ job = -1; time = 0; } }f[maxn]; int main() { int t; scanf("%d",&t); string op; for(int cas = 1;cas<=t;cas++) { memset(fa,-1,sizeof(fa)); int n; scanf("%d",&n); for(int i=1;i<=n;i++)f[i].job=-1,f[i].time=-1; for(int i=1;i<n;i++) { int u,v; scanf("%d %d",&u,&v); fa[u]=v; } int m; scanf("%d",&m); cout<<"Case #"<<cas<<":"<<endl; int tem = 0; while(m--) { cin>>op; if(op[0]=='C') { int x; scanf("%d",&x); int y = f[x].job; int temp = f[x].time; while(x!=-1) { if(f[x].time>temp) { temp = f[x].time; y= f[x].job; } x=fa[x]; } printf("%d\n",y); } else { int x,y; scanf("%d %d",&x,&y); f[x].job=y; f[x].time=++tem; } } } }
|