#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,tes,t,f[2009],i,j,tp,k[2009],lf[2009],rg[2009],tim,l,r,lc,msh[2009][11];
vector <int> v[2009];
int bo;
void dfs(int q, int w){
msh[q][0]=w;
for(int h=1; h<=10; h++) msh[q][h]=msh[msh[q][h-1]][h-1];
tim++;
lf[q]=rg[q]=tim;
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it)==w) continue;
dfs((*it),q);
if(rg[q]<rg[(*it)]) rg[q]=rg[(*it)];
}
}
bool anc(long long q, long long w){
if(lf[q]<=lf[w]&&rg[q]>=rg[w]) return 1; else return 0;
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>b>>tes;
for(i=1; i<a; i++){
cin>>c>>d;
v[c].push_back(d);
v[d].push_back(c);
}
dfs(1,0);
for(i=1; i<=b; i++) cin>>f[i];
for(t=1; t<=tes; t++){
cin>>tp;
if(tp==1){
cin>>c>>d;
f[c]=d;
continue;
}
cin>>l>>r>>lc;
bo=0;
for(i=l; i<=r; i++){
if(f[i]==lc){
bo=i;
break;
}
if(anc(lc,f[i])==0){
k[i]=0;
}else{
int ff=f[i];
for(j=10; j>=0; j--){
if(msh[ff][j]!=0&&anc(msh[ff][j],lc)==0) ff=msh[ff][j];
}
k[i]=ff;
}
}
if(bo!=0){
cout<<bo<<" "<<bo<<endl;
continue;
}
j=r+1;
pair <pair <int, int> , pair <int, int> > p;
bo=0;
for(i=r; i>=l; i--){
if(k[i]==0){
j=i;
continue;
}
c=0;
if(p.first.second!=k[i]) c=p.first.first; else c=p.second.first;
if(c!=0){
if(j>c){
cout<<i<<" "<<c<<endl;
bo=1;
break;
}
}
//
if(p.first.second!=k[i]){
p.second=p.first;
p.first.first=i;
p.first.second=k[i];
}else{
p.first.first=i;
}
}
if(bo==0){
cout<<"-1 -1"<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
376 KB |
n=100 |
3 |
Correct |
2 ms |
376 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
376 KB |
n=100 |
6 |
Correct |
3 ms |
376 KB |
n=100 |
7 |
Correct |
3 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
376 KB |
n=100 |
9 |
Correct |
2 ms |
376 KB |
n=100 |
10 |
Correct |
2 ms |
376 KB |
n=100 |
11 |
Correct |
2 ms |
376 KB |
n=100 |
12 |
Correct |
2 ms |
376 KB |
n=100 |
13 |
Correct |
2 ms |
376 KB |
n=100 |
14 |
Correct |
2 ms |
376 KB |
n=100 |
15 |
Correct |
3 ms |
376 KB |
n=100 |
16 |
Correct |
2 ms |
376 KB |
n=100 |
17 |
Correct |
3 ms |
376 KB |
n=100 |
18 |
Correct |
3 ms |
376 KB |
n=100 |
19 |
Correct |
2 ms |
376 KB |
n=100 |
20 |
Correct |
2 ms |
376 KB |
n=100 |
21 |
Correct |
2 ms |
376 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
2 ms |
376 KB |
n=100 |
24 |
Correct |
2 ms |
376 KB |
n=100 |
25 |
Correct |
2 ms |
376 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
3 ms |
376 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
376 KB |
n=100 |
3 |
Correct |
2 ms |
376 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
376 KB |
n=100 |
6 |
Correct |
3 ms |
376 KB |
n=100 |
7 |
Correct |
3 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
376 KB |
n=100 |
9 |
Correct |
2 ms |
376 KB |
n=100 |
10 |
Correct |
2 ms |
376 KB |
n=100 |
11 |
Correct |
2 ms |
376 KB |
n=100 |
12 |
Correct |
2 ms |
376 KB |
n=100 |
13 |
Correct |
2 ms |
376 KB |
n=100 |
14 |
Correct |
2 ms |
376 KB |
n=100 |
15 |
Correct |
3 ms |
376 KB |
n=100 |
16 |
Correct |
2 ms |
376 KB |
n=100 |
17 |
Correct |
3 ms |
376 KB |
n=100 |
18 |
Correct |
3 ms |
376 KB |
n=100 |
19 |
Correct |
2 ms |
376 KB |
n=100 |
20 |
Correct |
2 ms |
376 KB |
n=100 |
21 |
Correct |
2 ms |
376 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
2 ms |
376 KB |
n=100 |
24 |
Correct |
2 ms |
376 KB |
n=100 |
25 |
Correct |
2 ms |
376 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
3 ms |
376 KB |
n=100 |
28 |
Correct |
4 ms |
376 KB |
n=500 |
29 |
Correct |
5 ms |
508 KB |
n=500 |
30 |
Correct |
5 ms |
376 KB |
n=500 |
31 |
Correct |
5 ms |
504 KB |
n=500 |
32 |
Correct |
4 ms |
504 KB |
n=500 |
33 |
Correct |
5 ms |
504 KB |
n=500 |
34 |
Correct |
4 ms |
376 KB |
n=500 |
35 |
Correct |
5 ms |
504 KB |
n=500 |
36 |
Correct |
7 ms |
504 KB |
n=500 |
37 |
Correct |
7 ms |
504 KB |
n=500 |
38 |
Correct |
7 ms |
504 KB |
n=500 |
39 |
Correct |
5 ms |
504 KB |
n=500 |
40 |
Correct |
5 ms |
504 KB |
n=500 |
41 |
Correct |
5 ms |
380 KB |
n=500 |
42 |
Correct |
5 ms |
376 KB |
n=500 |
43 |
Correct |
5 ms |
376 KB |
n=500 |
44 |
Correct |
5 ms |
504 KB |
n=500 |
45 |
Correct |
3 ms |
504 KB |
n=500 |
46 |
Correct |
5 ms |
504 KB |
n=500 |
47 |
Correct |
5 ms |
504 KB |
n=500 |
48 |
Correct |
3 ms |
508 KB |
n=500 |
49 |
Correct |
4 ms |
504 KB |
n=500 |
50 |
Correct |
3 ms |
376 KB |
n=500 |
51 |
Correct |
4 ms |
504 KB |
n=500 |
52 |
Correct |
6 ms |
504 KB |
n=500 |
53 |
Correct |
4 ms |
504 KB |
n=500 |
54 |
Correct |
8 ms |
504 KB |
n=500 |
55 |
Correct |
3 ms |
376 KB |
n=278 |
56 |
Correct |
8 ms |
504 KB |
n=500 |
57 |
Correct |
8 ms |
504 KB |
n=500 |
58 |
Correct |
4 ms |
376 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
376 KB |
n=100 |
3 |
Correct |
2 ms |
376 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
376 KB |
n=100 |
6 |
Correct |
3 ms |
376 KB |
n=100 |
7 |
Correct |
3 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
376 KB |
n=100 |
9 |
Correct |
2 ms |
376 KB |
n=100 |
10 |
Correct |
2 ms |
376 KB |
n=100 |
11 |
Correct |
2 ms |
376 KB |
n=100 |
12 |
Correct |
2 ms |
376 KB |
n=100 |
13 |
Correct |
2 ms |
376 KB |
n=100 |
14 |
Correct |
2 ms |
376 KB |
n=100 |
15 |
Correct |
3 ms |
376 KB |
n=100 |
16 |
Correct |
2 ms |
376 KB |
n=100 |
17 |
Correct |
3 ms |
376 KB |
n=100 |
18 |
Correct |
3 ms |
376 KB |
n=100 |
19 |
Correct |
2 ms |
376 KB |
n=100 |
20 |
Correct |
2 ms |
376 KB |
n=100 |
21 |
Correct |
2 ms |
376 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
2 ms |
376 KB |
n=100 |
24 |
Correct |
2 ms |
376 KB |
n=100 |
25 |
Correct |
2 ms |
376 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
3 ms |
376 KB |
n=100 |
28 |
Correct |
4 ms |
376 KB |
n=500 |
29 |
Correct |
5 ms |
508 KB |
n=500 |
30 |
Correct |
5 ms |
376 KB |
n=500 |
31 |
Correct |
5 ms |
504 KB |
n=500 |
32 |
Correct |
4 ms |
504 KB |
n=500 |
33 |
Correct |
5 ms |
504 KB |
n=500 |
34 |
Correct |
4 ms |
376 KB |
n=500 |
35 |
Correct |
5 ms |
504 KB |
n=500 |
36 |
Correct |
7 ms |
504 KB |
n=500 |
37 |
Correct |
7 ms |
504 KB |
n=500 |
38 |
Correct |
7 ms |
504 KB |
n=500 |
39 |
Correct |
5 ms |
504 KB |
n=500 |
40 |
Correct |
5 ms |
504 KB |
n=500 |
41 |
Correct |
5 ms |
380 KB |
n=500 |
42 |
Correct |
5 ms |
376 KB |
n=500 |
43 |
Correct |
5 ms |
376 KB |
n=500 |
44 |
Correct |
5 ms |
504 KB |
n=500 |
45 |
Correct |
3 ms |
504 KB |
n=500 |
46 |
Correct |
5 ms |
504 KB |
n=500 |
47 |
Correct |
5 ms |
504 KB |
n=500 |
48 |
Correct |
3 ms |
508 KB |
n=500 |
49 |
Correct |
4 ms |
504 KB |
n=500 |
50 |
Correct |
3 ms |
376 KB |
n=500 |
51 |
Correct |
4 ms |
504 KB |
n=500 |
52 |
Correct |
6 ms |
504 KB |
n=500 |
53 |
Correct |
4 ms |
504 KB |
n=500 |
54 |
Correct |
8 ms |
504 KB |
n=500 |
55 |
Correct |
3 ms |
376 KB |
n=278 |
56 |
Correct |
8 ms |
504 KB |
n=500 |
57 |
Correct |
8 ms |
504 KB |
n=500 |
58 |
Correct |
4 ms |
376 KB |
n=500 |
59 |
Correct |
15 ms |
632 KB |
n=2000 |
60 |
Correct |
39 ms |
760 KB |
n=2000 |
61 |
Correct |
41 ms |
632 KB |
n=2000 |
62 |
Correct |
42 ms |
632 KB |
n=2000 |
63 |
Correct |
22 ms |
632 KB |
n=2000 |
64 |
Correct |
44 ms |
760 KB |
n=2000 |
65 |
Correct |
23 ms |
760 KB |
n=2000 |
66 |
Correct |
42 ms |
760 KB |
n=2000 |
67 |
Correct |
27 ms |
760 KB |
n=2000 |
68 |
Correct |
41 ms |
632 KB |
n=2000 |
69 |
Correct |
79 ms |
760 KB |
n=2000 |
70 |
Correct |
77 ms |
692 KB |
n=2000 |
71 |
Correct |
75 ms |
760 KB |
n=2000 |
72 |
Correct |
25 ms |
632 KB |
n=2000 |
73 |
Correct |
23 ms |
632 KB |
n=2000 |
74 |
Correct |
11 ms |
632 KB |
n=1844 |
75 |
Correct |
25 ms |
632 KB |
n=2000 |
76 |
Correct |
37 ms |
632 KB |
n=2000 |
77 |
Correct |
42 ms |
632 KB |
n=2000 |
78 |
Correct |
43 ms |
680 KB |
n=2000 |
79 |
Correct |
7 ms |
604 KB |
n=2000 |
80 |
Correct |
35 ms |
760 KB |
n=2000 |
81 |
Correct |
37 ms |
632 KB |
n=2000 |
82 |
Correct |
7 ms |
636 KB |
n=2000 |
83 |
Correct |
37 ms |
632 KB |
n=2000 |
84 |
Correct |
10 ms |
632 KB |
n=2000 |
85 |
Correct |
27 ms |
632 KB |
n=2000 |
86 |
Correct |
22 ms |
632 KB |
n=2000 |
87 |
Correct |
10 ms |
632 KB |
n=2000 |
88 |
Correct |
198 ms |
760 KB |
n=2000 |
89 |
Correct |
198 ms |
760 KB |
n=2000 |
90 |
Correct |
164 ms |
860 KB |
n=2000 |
91 |
Correct |
14 ms |
632 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=5 |
2 |
Correct |
2 ms |
376 KB |
n=100 |
3 |
Correct |
2 ms |
376 KB |
n=100 |
4 |
Correct |
2 ms |
376 KB |
n=100 |
5 |
Correct |
2 ms |
376 KB |
n=100 |
6 |
Correct |
3 ms |
376 KB |
n=100 |
7 |
Correct |
3 ms |
504 KB |
n=100 |
8 |
Correct |
2 ms |
376 KB |
n=100 |
9 |
Correct |
2 ms |
376 KB |
n=100 |
10 |
Correct |
2 ms |
376 KB |
n=100 |
11 |
Correct |
2 ms |
376 KB |
n=100 |
12 |
Correct |
2 ms |
376 KB |
n=100 |
13 |
Correct |
2 ms |
376 KB |
n=100 |
14 |
Correct |
2 ms |
376 KB |
n=100 |
15 |
Correct |
3 ms |
376 KB |
n=100 |
16 |
Correct |
2 ms |
376 KB |
n=100 |
17 |
Correct |
3 ms |
376 KB |
n=100 |
18 |
Correct |
3 ms |
376 KB |
n=100 |
19 |
Correct |
2 ms |
376 KB |
n=100 |
20 |
Correct |
2 ms |
376 KB |
n=100 |
21 |
Correct |
2 ms |
376 KB |
n=100 |
22 |
Correct |
2 ms |
376 KB |
n=100 |
23 |
Correct |
2 ms |
376 KB |
n=100 |
24 |
Correct |
2 ms |
376 KB |
n=100 |
25 |
Correct |
2 ms |
376 KB |
n=100 |
26 |
Correct |
2 ms |
376 KB |
n=12 |
27 |
Correct |
3 ms |
376 KB |
n=100 |
28 |
Correct |
4 ms |
376 KB |
n=500 |
29 |
Correct |
5 ms |
508 KB |
n=500 |
30 |
Correct |
5 ms |
376 KB |
n=500 |
31 |
Correct |
5 ms |
504 KB |
n=500 |
32 |
Correct |
4 ms |
504 KB |
n=500 |
33 |
Correct |
5 ms |
504 KB |
n=500 |
34 |
Correct |
4 ms |
376 KB |
n=500 |
35 |
Correct |
5 ms |
504 KB |
n=500 |
36 |
Correct |
7 ms |
504 KB |
n=500 |
37 |
Correct |
7 ms |
504 KB |
n=500 |
38 |
Correct |
7 ms |
504 KB |
n=500 |
39 |
Correct |
5 ms |
504 KB |
n=500 |
40 |
Correct |
5 ms |
504 KB |
n=500 |
41 |
Correct |
5 ms |
380 KB |
n=500 |
42 |
Correct |
5 ms |
376 KB |
n=500 |
43 |
Correct |
5 ms |
376 KB |
n=500 |
44 |
Correct |
5 ms |
504 KB |
n=500 |
45 |
Correct |
3 ms |
504 KB |
n=500 |
46 |
Correct |
5 ms |
504 KB |
n=500 |
47 |
Correct |
5 ms |
504 KB |
n=500 |
48 |
Correct |
3 ms |
508 KB |
n=500 |
49 |
Correct |
4 ms |
504 KB |
n=500 |
50 |
Correct |
3 ms |
376 KB |
n=500 |
51 |
Correct |
4 ms |
504 KB |
n=500 |
52 |
Correct |
6 ms |
504 KB |
n=500 |
53 |
Correct |
4 ms |
504 KB |
n=500 |
54 |
Correct |
8 ms |
504 KB |
n=500 |
55 |
Correct |
3 ms |
376 KB |
n=278 |
56 |
Correct |
8 ms |
504 KB |
n=500 |
57 |
Correct |
8 ms |
504 KB |
n=500 |
58 |
Correct |
4 ms |
376 KB |
n=500 |
59 |
Correct |
15 ms |
632 KB |
n=2000 |
60 |
Correct |
39 ms |
760 KB |
n=2000 |
61 |
Correct |
41 ms |
632 KB |
n=2000 |
62 |
Correct |
42 ms |
632 KB |
n=2000 |
63 |
Correct |
22 ms |
632 KB |
n=2000 |
64 |
Correct |
44 ms |
760 KB |
n=2000 |
65 |
Correct |
23 ms |
760 KB |
n=2000 |
66 |
Correct |
42 ms |
760 KB |
n=2000 |
67 |
Correct |
27 ms |
760 KB |
n=2000 |
68 |
Correct |
41 ms |
632 KB |
n=2000 |
69 |
Correct |
79 ms |
760 KB |
n=2000 |
70 |
Correct |
77 ms |
692 KB |
n=2000 |
71 |
Correct |
75 ms |
760 KB |
n=2000 |
72 |
Correct |
25 ms |
632 KB |
n=2000 |
73 |
Correct |
23 ms |
632 KB |
n=2000 |
74 |
Correct |
11 ms |
632 KB |
n=1844 |
75 |
Correct |
25 ms |
632 KB |
n=2000 |
76 |
Correct |
37 ms |
632 KB |
n=2000 |
77 |
Correct |
42 ms |
632 KB |
n=2000 |
78 |
Correct |
43 ms |
680 KB |
n=2000 |
79 |
Correct |
7 ms |
604 KB |
n=2000 |
80 |
Correct |
35 ms |
760 KB |
n=2000 |
81 |
Correct |
37 ms |
632 KB |
n=2000 |
82 |
Correct |
7 ms |
636 KB |
n=2000 |
83 |
Correct |
37 ms |
632 KB |
n=2000 |
84 |
Correct |
10 ms |
632 KB |
n=2000 |
85 |
Correct |
27 ms |
632 KB |
n=2000 |
86 |
Correct |
22 ms |
632 KB |
n=2000 |
87 |
Correct |
10 ms |
632 KB |
n=2000 |
88 |
Correct |
198 ms |
760 KB |
n=2000 |
89 |
Correct |
198 ms |
760 KB |
n=2000 |
90 |
Correct |
164 ms |
860 KB |
n=2000 |
91 |
Correct |
14 ms |
632 KB |
n=2000 |
92 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
93 |
Halted |
0 ms |
0 KB |
- |