#include <bits/stdc++.h>
//#include "boxes.h"
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=2e5+5;
vector <int> g[N];
int p[N],d[N],jmp[N][20];
void dfs(int v,int par){
p[v]=par;
for(auto to : g[v]){
if(to!=par){
d[to]=d[v]+1;
dfs(to,v);
}
}
}
int lca(int a,int b){
if(d[a]<d[b])swap(a,b);
for(int i=19;i>=0;i--){
if(d[jmp[a][i]]>=d[b]){
a=jmp[a][i];
}
}
if(a==b)return a;
for(int i=19;i>=0;i--){
if(jmp[a][i]!=jmp[b][i]){
a=jmp[a][i];
b=jmp[b][i];
}
}
return p[a];
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
for(int i=0;i<n-1;i++){
int u,v;
cin>>u>>v;
g[u].pb(v);g[v].pb(u);
}
dfs(1,1);
for(int i=1;i<=n;i++){
jmp[i][0]=p[i];
}
for(int i=1;i<20;i++){
for(int j=1;j<=n;j++){
jmp[j][i]=jmp[jmp[j][i-1]][i-1];
}
}
/*for(int i=1;i<=n;i++)cout<<d[i]<<" ";
cout<<"\n";
for(int i=1;i<=n;i++){
for(int j=0;j<20;j++){
cout<<jmp[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n";*/
vector <int> a(m+1);
for(int i=1;i<=m;i++)cin>>a[i];
while(q--){
int type,l,r,v,pos;
cin>>type;
if(type==1){
cin>>pos>>v;
a[pos]=v;
}
else{
cin>>l>>r>>v;
int st=l,x=a[l];
int L=-1,R=-1;
for(int i=l;i<=r;i++){
if(lca(a[i],v)!=v){
if(st<i && x==v){
L=st;R=i-1;break;
}
st=i+1;
if(i+1<=m)x=a[st];
continue;
}
x=lca(x,a[i]);
}
if(x==v && st<=r && L==-1 && R==-1){
L=st;R=r;
}
cout<<L<<" "<<R<<"\n";
}
}
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7772 KB |
n=5 |
2 |
Correct |
2 ms |
7772 KB |
n=100 |
3 |
Correct |
2 ms |
7768 KB |
n=100 |
4 |
Correct |
3 ms |
7772 KB |
n=100 |
5 |
Correct |
2 ms |
7768 KB |
n=100 |
6 |
Correct |
3 ms |
7768 KB |
n=100 |
7 |
Correct |
3 ms |
7772 KB |
n=100 |
8 |
Correct |
3 ms |
7768 KB |
n=100 |
9 |
Correct |
2 ms |
7772 KB |
n=100 |
10 |
Correct |
2 ms |
7772 KB |
n=100 |
11 |
Correct |
3 ms |
7824 KB |
n=100 |
12 |
Correct |
2 ms |
7772 KB |
n=100 |
13 |
Correct |
2 ms |
7772 KB |
n=100 |
14 |
Correct |
2 ms |
7768 KB |
n=100 |
15 |
Correct |
2 ms |
8028 KB |
n=100 |
16 |
Correct |
2 ms |
7772 KB |
n=100 |
17 |
Correct |
2 ms |
7772 KB |
n=100 |
18 |
Correct |
2 ms |
7772 KB |
n=100 |
19 |
Correct |
2 ms |
7748 KB |
n=100 |
20 |
Correct |
2 ms |
7772 KB |
n=100 |
21 |
Correct |
2 ms |
7772 KB |
n=100 |
22 |
Correct |
2 ms |
7772 KB |
n=100 |
23 |
Correct |
2 ms |
7772 KB |
n=100 |
24 |
Correct |
2 ms |
7772 KB |
n=100 |
25 |
Correct |
3 ms |
7768 KB |
n=100 |
26 |
Correct |
2 ms |
7768 KB |
n=12 |
27 |
Correct |
3 ms |
7772 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7772 KB |
n=5 |
2 |
Correct |
2 ms |
7772 KB |
n=100 |
3 |
Correct |
2 ms |
7768 KB |
n=100 |
4 |
Correct |
3 ms |
7772 KB |
n=100 |
5 |
Correct |
2 ms |
7768 KB |
n=100 |
6 |
Correct |
3 ms |
7768 KB |
n=100 |
7 |
Correct |
3 ms |
7772 KB |
n=100 |
8 |
Correct |
3 ms |
7768 KB |
n=100 |
9 |
Correct |
2 ms |
7772 KB |
n=100 |
10 |
Correct |
2 ms |
7772 KB |
n=100 |
11 |
Correct |
3 ms |
7824 KB |
n=100 |
12 |
Correct |
2 ms |
7772 KB |
n=100 |
13 |
Correct |
2 ms |
7772 KB |
n=100 |
14 |
Correct |
2 ms |
7768 KB |
n=100 |
15 |
Correct |
2 ms |
8028 KB |
n=100 |
16 |
Correct |
2 ms |
7772 KB |
n=100 |
17 |
Correct |
2 ms |
7772 KB |
n=100 |
18 |
Correct |
2 ms |
7772 KB |
n=100 |
19 |
Correct |
2 ms |
7748 KB |
n=100 |
20 |
Correct |
2 ms |
7772 KB |
n=100 |
21 |
Correct |
2 ms |
7772 KB |
n=100 |
22 |
Correct |
2 ms |
7772 KB |
n=100 |
23 |
Correct |
2 ms |
7772 KB |
n=100 |
24 |
Correct |
2 ms |
7772 KB |
n=100 |
25 |
Correct |
3 ms |
7768 KB |
n=100 |
26 |
Correct |
2 ms |
7768 KB |
n=12 |
27 |
Correct |
3 ms |
7772 KB |
n=100 |
28 |
Correct |
10 ms |
7768 KB |
n=500 |
29 |
Correct |
6 ms |
7768 KB |
n=500 |
30 |
Correct |
6 ms |
7772 KB |
n=500 |
31 |
Correct |
6 ms |
7772 KB |
n=500 |
32 |
Correct |
11 ms |
7772 KB |
n=500 |
33 |
Correct |
5 ms |
7772 KB |
n=500 |
34 |
Correct |
11 ms |
7768 KB |
n=500 |
35 |
Correct |
6 ms |
7772 KB |
n=500 |
36 |
Correct |
22 ms |
8024 KB |
n=500 |
37 |
Correct |
23 ms |
7768 KB |
n=500 |
38 |
Correct |
22 ms |
7772 KB |
n=500 |
39 |
Correct |
13 ms |
7872 KB |
n=500 |
40 |
Correct |
12 ms |
7772 KB |
n=500 |
41 |
Correct |
14 ms |
7772 KB |
n=500 |
42 |
Correct |
12 ms |
7772 KB |
n=500 |
43 |
Correct |
13 ms |
7768 KB |
n=500 |
44 |
Correct |
12 ms |
7772 KB |
n=500 |
45 |
Correct |
9 ms |
7772 KB |
n=500 |
46 |
Correct |
6 ms |
7772 KB |
n=500 |
47 |
Correct |
5 ms |
7772 KB |
n=500 |
48 |
Correct |
9 ms |
7772 KB |
n=500 |
49 |
Correct |
6 ms |
7772 KB |
n=500 |
50 |
Correct |
7 ms |
7772 KB |
n=500 |
51 |
Correct |
7 ms |
7772 KB |
n=500 |
52 |
Correct |
8 ms |
7768 KB |
n=500 |
53 |
Correct |
7 ms |
7772 KB |
n=500 |
54 |
Correct |
21 ms |
7772 KB |
n=500 |
55 |
Correct |
3 ms |
7768 KB |
n=278 |
56 |
Correct |
21 ms |
7772 KB |
n=500 |
57 |
Correct |
21 ms |
7772 KB |
n=500 |
58 |
Correct |
16 ms |
7876 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7772 KB |
n=5 |
2 |
Correct |
2 ms |
7772 KB |
n=100 |
3 |
Correct |
2 ms |
7768 KB |
n=100 |
4 |
Correct |
3 ms |
7772 KB |
n=100 |
5 |
Correct |
2 ms |
7768 KB |
n=100 |
6 |
Correct |
3 ms |
7768 KB |
n=100 |
7 |
Correct |
3 ms |
7772 KB |
n=100 |
8 |
Correct |
3 ms |
7768 KB |
n=100 |
9 |
Correct |
2 ms |
7772 KB |
n=100 |
10 |
Correct |
2 ms |
7772 KB |
n=100 |
11 |
Correct |
3 ms |
7824 KB |
n=100 |
12 |
Correct |
2 ms |
7772 KB |
n=100 |
13 |
Correct |
2 ms |
7772 KB |
n=100 |
14 |
Correct |
2 ms |
7768 KB |
n=100 |
15 |
Correct |
2 ms |
8028 KB |
n=100 |
16 |
Correct |
2 ms |
7772 KB |
n=100 |
17 |
Correct |
2 ms |
7772 KB |
n=100 |
18 |
Correct |
2 ms |
7772 KB |
n=100 |
19 |
Correct |
2 ms |
7748 KB |
n=100 |
20 |
Correct |
2 ms |
7772 KB |
n=100 |
21 |
Correct |
2 ms |
7772 KB |
n=100 |
22 |
Correct |
2 ms |
7772 KB |
n=100 |
23 |
Correct |
2 ms |
7772 KB |
n=100 |
24 |
Correct |
2 ms |
7772 KB |
n=100 |
25 |
Correct |
3 ms |
7768 KB |
n=100 |
26 |
Correct |
2 ms |
7768 KB |
n=12 |
27 |
Correct |
3 ms |
7772 KB |
n=100 |
28 |
Correct |
10 ms |
7768 KB |
n=500 |
29 |
Correct |
6 ms |
7768 KB |
n=500 |
30 |
Correct |
6 ms |
7772 KB |
n=500 |
31 |
Correct |
6 ms |
7772 KB |
n=500 |
32 |
Correct |
11 ms |
7772 KB |
n=500 |
33 |
Correct |
5 ms |
7772 KB |
n=500 |
34 |
Correct |
11 ms |
7768 KB |
n=500 |
35 |
Correct |
6 ms |
7772 KB |
n=500 |
36 |
Correct |
22 ms |
8024 KB |
n=500 |
37 |
Correct |
23 ms |
7768 KB |
n=500 |
38 |
Correct |
22 ms |
7772 KB |
n=500 |
39 |
Correct |
13 ms |
7872 KB |
n=500 |
40 |
Correct |
12 ms |
7772 KB |
n=500 |
41 |
Correct |
14 ms |
7772 KB |
n=500 |
42 |
Correct |
12 ms |
7772 KB |
n=500 |
43 |
Correct |
13 ms |
7768 KB |
n=500 |
44 |
Correct |
12 ms |
7772 KB |
n=500 |
45 |
Correct |
9 ms |
7772 KB |
n=500 |
46 |
Correct |
6 ms |
7772 KB |
n=500 |
47 |
Correct |
5 ms |
7772 KB |
n=500 |
48 |
Correct |
9 ms |
7772 KB |
n=500 |
49 |
Correct |
6 ms |
7772 KB |
n=500 |
50 |
Correct |
7 ms |
7772 KB |
n=500 |
51 |
Correct |
7 ms |
7772 KB |
n=500 |
52 |
Correct |
8 ms |
7768 KB |
n=500 |
53 |
Correct |
7 ms |
7772 KB |
n=500 |
54 |
Correct |
21 ms |
7772 KB |
n=500 |
55 |
Correct |
3 ms |
7768 KB |
n=278 |
56 |
Correct |
21 ms |
7772 KB |
n=500 |
57 |
Correct |
21 ms |
7772 KB |
n=500 |
58 |
Correct |
16 ms |
7876 KB |
n=500 |
59 |
Correct |
123 ms |
8028 KB |
n=2000 |
60 |
Correct |
57 ms |
8140 KB |
n=2000 |
61 |
Correct |
54 ms |
8024 KB |
n=2000 |
62 |
Correct |
42 ms |
8076 KB |
n=2000 |
63 |
Correct |
131 ms |
8044 KB |
n=2000 |
64 |
Correct |
52 ms |
8080 KB |
n=2000 |
65 |
Correct |
137 ms |
8056 KB |
n=2000 |
66 |
Correct |
61 ms |
8132 KB |
n=2000 |
67 |
Correct |
84 ms |
8040 KB |
n=2000 |
68 |
Correct |
53 ms |
8104 KB |
n=2000 |
69 |
Correct |
328 ms |
8276 KB |
n=2000 |
70 |
Correct |
314 ms |
8028 KB |
n=2000 |
71 |
Correct |
320 ms |
8028 KB |
n=2000 |
72 |
Correct |
160 ms |
8028 KB |
n=2000 |
73 |
Correct |
160 ms |
8024 KB |
n=2000 |
74 |
Correct |
105 ms |
8028 KB |
n=1844 |
75 |
Correct |
163 ms |
8024 KB |
n=2000 |
76 |
Correct |
166 ms |
8028 KB |
n=2000 |
77 |
Correct |
171 ms |
8028 KB |
n=2000 |
78 |
Correct |
201 ms |
8020 KB |
n=2000 |
79 |
Correct |
116 ms |
8028 KB |
n=2000 |
80 |
Correct |
50 ms |
8028 KB |
n=2000 |
81 |
Correct |
53 ms |
8280 KB |
n=2000 |
82 |
Correct |
108 ms |
8028 KB |
n=2000 |
83 |
Correct |
50 ms |
8024 KB |
n=2000 |
84 |
Correct |
83 ms |
8036 KB |
n=2000 |
85 |
Correct |
93 ms |
8272 KB |
n=2000 |
86 |
Correct |
88 ms |
8024 KB |
n=2000 |
87 |
Correct |
88 ms |
8028 KB |
n=2000 |
88 |
Correct |
378 ms |
8164 KB |
n=2000 |
89 |
Correct |
340 ms |
8144 KB |
n=2000 |
90 |
Correct |
287 ms |
8028 KB |
n=2000 |
91 |
Correct |
226 ms |
8028 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7772 KB |
n=5 |
2 |
Correct |
2 ms |
7772 KB |
n=100 |
3 |
Correct |
2 ms |
7768 KB |
n=100 |
4 |
Correct |
3 ms |
7772 KB |
n=100 |
5 |
Correct |
2 ms |
7768 KB |
n=100 |
6 |
Correct |
3 ms |
7768 KB |
n=100 |
7 |
Correct |
3 ms |
7772 KB |
n=100 |
8 |
Correct |
3 ms |
7768 KB |
n=100 |
9 |
Correct |
2 ms |
7772 KB |
n=100 |
10 |
Correct |
2 ms |
7772 KB |
n=100 |
11 |
Correct |
3 ms |
7824 KB |
n=100 |
12 |
Correct |
2 ms |
7772 KB |
n=100 |
13 |
Correct |
2 ms |
7772 KB |
n=100 |
14 |
Correct |
2 ms |
7768 KB |
n=100 |
15 |
Correct |
2 ms |
8028 KB |
n=100 |
16 |
Correct |
2 ms |
7772 KB |
n=100 |
17 |
Correct |
2 ms |
7772 KB |
n=100 |
18 |
Correct |
2 ms |
7772 KB |
n=100 |
19 |
Correct |
2 ms |
7748 KB |
n=100 |
20 |
Correct |
2 ms |
7772 KB |
n=100 |
21 |
Correct |
2 ms |
7772 KB |
n=100 |
22 |
Correct |
2 ms |
7772 KB |
n=100 |
23 |
Correct |
2 ms |
7772 KB |
n=100 |
24 |
Correct |
2 ms |
7772 KB |
n=100 |
25 |
Correct |
3 ms |
7768 KB |
n=100 |
26 |
Correct |
2 ms |
7768 KB |
n=12 |
27 |
Correct |
3 ms |
7772 KB |
n=100 |
28 |
Correct |
10 ms |
7768 KB |
n=500 |
29 |
Correct |
6 ms |
7768 KB |
n=500 |
30 |
Correct |
6 ms |
7772 KB |
n=500 |
31 |
Correct |
6 ms |
7772 KB |
n=500 |
32 |
Correct |
11 ms |
7772 KB |
n=500 |
33 |
Correct |
5 ms |
7772 KB |
n=500 |
34 |
Correct |
11 ms |
7768 KB |
n=500 |
35 |
Correct |
6 ms |
7772 KB |
n=500 |
36 |
Correct |
22 ms |
8024 KB |
n=500 |
37 |
Correct |
23 ms |
7768 KB |
n=500 |
38 |
Correct |
22 ms |
7772 KB |
n=500 |
39 |
Correct |
13 ms |
7872 KB |
n=500 |
40 |
Correct |
12 ms |
7772 KB |
n=500 |
41 |
Correct |
14 ms |
7772 KB |
n=500 |
42 |
Correct |
12 ms |
7772 KB |
n=500 |
43 |
Correct |
13 ms |
7768 KB |
n=500 |
44 |
Correct |
12 ms |
7772 KB |
n=500 |
45 |
Correct |
9 ms |
7772 KB |
n=500 |
46 |
Correct |
6 ms |
7772 KB |
n=500 |
47 |
Correct |
5 ms |
7772 KB |
n=500 |
48 |
Correct |
9 ms |
7772 KB |
n=500 |
49 |
Correct |
6 ms |
7772 KB |
n=500 |
50 |
Correct |
7 ms |
7772 KB |
n=500 |
51 |
Correct |
7 ms |
7772 KB |
n=500 |
52 |
Correct |
8 ms |
7768 KB |
n=500 |
53 |
Correct |
7 ms |
7772 KB |
n=500 |
54 |
Correct |
21 ms |
7772 KB |
n=500 |
55 |
Correct |
3 ms |
7768 KB |
n=278 |
56 |
Correct |
21 ms |
7772 KB |
n=500 |
57 |
Correct |
21 ms |
7772 KB |
n=500 |
58 |
Correct |
16 ms |
7876 KB |
n=500 |
59 |
Correct |
123 ms |
8028 KB |
n=2000 |
60 |
Correct |
57 ms |
8140 KB |
n=2000 |
61 |
Correct |
54 ms |
8024 KB |
n=2000 |
62 |
Correct |
42 ms |
8076 KB |
n=2000 |
63 |
Correct |
131 ms |
8044 KB |
n=2000 |
64 |
Correct |
52 ms |
8080 KB |
n=2000 |
65 |
Correct |
137 ms |
8056 KB |
n=2000 |
66 |
Correct |
61 ms |
8132 KB |
n=2000 |
67 |
Correct |
84 ms |
8040 KB |
n=2000 |
68 |
Correct |
53 ms |
8104 KB |
n=2000 |
69 |
Correct |
328 ms |
8276 KB |
n=2000 |
70 |
Correct |
314 ms |
8028 KB |
n=2000 |
71 |
Correct |
320 ms |
8028 KB |
n=2000 |
72 |
Correct |
160 ms |
8028 KB |
n=2000 |
73 |
Correct |
160 ms |
8024 KB |
n=2000 |
74 |
Correct |
105 ms |
8028 KB |
n=1844 |
75 |
Correct |
163 ms |
8024 KB |
n=2000 |
76 |
Correct |
166 ms |
8028 KB |
n=2000 |
77 |
Correct |
171 ms |
8028 KB |
n=2000 |
78 |
Correct |
201 ms |
8020 KB |
n=2000 |
79 |
Correct |
116 ms |
8028 KB |
n=2000 |
80 |
Correct |
50 ms |
8028 KB |
n=2000 |
81 |
Correct |
53 ms |
8280 KB |
n=2000 |
82 |
Correct |
108 ms |
8028 KB |
n=2000 |
83 |
Correct |
50 ms |
8024 KB |
n=2000 |
84 |
Correct |
83 ms |
8036 KB |
n=2000 |
85 |
Correct |
93 ms |
8272 KB |
n=2000 |
86 |
Correct |
88 ms |
8024 KB |
n=2000 |
87 |
Correct |
88 ms |
8028 KB |
n=2000 |
88 |
Correct |
378 ms |
8164 KB |
n=2000 |
89 |
Correct |
340 ms |
8144 KB |
n=2000 |
90 |
Correct |
287 ms |
8028 KB |
n=2000 |
91 |
Correct |
226 ms |
8028 KB |
n=2000 |
92 |
Execution timed out |
4030 ms |
33616 KB |
Time limit exceeded |
93 |
Halted |
0 ms |
0 KB |
- |