#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define _all(T) T.begin(),T.end()
const int mxn = 2e5+10;
vector<int> paths[mxn];
int fa[mxn],link_top[mxn],bs[mxn],sz[mxn],dep[mxn],arr[mxn];
void dfs1(int now,int par){
fa[now] = par;
sz[now] = 1;
for(auto nxt:paths[now]){
if(nxt == par)continue;
dep[nxt] = dep[now]+1;
dfs1(nxt,now);
if(bs[now] == 0||sz[bs[now]] < sz[nxt])bs[now] = nxt;
sz[now] += sz[nxt];
}
return;
}
void dfs2(int now,int top){
link_top[now] = top;
if(bs[now])dfs2(bs[now],top);
for(auto nxt:paths[now]){
if(nxt == fa[now]||nxt == bs[now])continue;
dfs2(nxt,nxt);
}
return;
}
int lca(int a,int b){
int ta = link_top[a],tb = link_top[b];
while(ta != tb){
if(dep[ta]<dep[tb]){
swap(ta,tb);
swap(a,b);
}
a = fa[ta];
ta = link_top[a];
}
if(dep[a]>dep[b])return b;
else return a;
}
int main(){
io
int n,m,q;
cin>>n>>m>>q;
// if(m*m*q*__lg(n)>=1e9)return 0;
for(int i = 0;i<n-1;i++){
int a,b;
cin>>a>>b;
paths[a].push_back(b);
paths[b].push_back(a);
}
dfs1(1,1);
dfs2(1,1);
for(int i = 1;i<=m;i++){
cin>>arr[i];
}
// cout<<lca(3,4);
while(q--){
int t;
cin>>t;
if(t == 1){
int p,v;
cin>>p>>v;
arr[p] = v;
}
else{
int l,r,v;
cin>>l>>r>>v;
pii ans = {-1,-1};
for(int i = l;i<=r;i++){
int now = arr[i];
for(int j= i;j<=r;j++){
now = lca(now,arr[j]);
if(now == v){
ans = {i,j};
}
}
}
cout<<ans.fs<<' '<<ans.sc<<'\n';
}
}
return 0;
}
/*
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
n=5 |
2 |
Correct |
4 ms |
4948 KB |
n=100 |
3 |
Correct |
4 ms |
4948 KB |
n=100 |
4 |
Correct |
4 ms |
5028 KB |
n=100 |
5 |
Correct |
4 ms |
5020 KB |
n=100 |
6 |
Correct |
6 ms |
4948 KB |
n=100 |
7 |
Correct |
6 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
4 ms |
5056 KB |
n=100 |
10 |
Correct |
5 ms |
4948 KB |
n=100 |
11 |
Correct |
4 ms |
5024 KB |
n=100 |
12 |
Correct |
5 ms |
4948 KB |
n=100 |
13 |
Correct |
5 ms |
4968 KB |
n=100 |
14 |
Correct |
3 ms |
5024 KB |
n=100 |
15 |
Correct |
3 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
5020 KB |
n=100 |
17 |
Correct |
3 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
3 ms |
4948 KB |
n=100 |
20 |
Correct |
4 ms |
4948 KB |
n=100 |
21 |
Correct |
3 ms |
4948 KB |
n=100 |
22 |
Correct |
3 ms |
4948 KB |
n=100 |
23 |
Correct |
3 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
4 ms |
4948 KB |
n=100 |
26 |
Correct |
3 ms |
4964 KB |
n=12 |
27 |
Correct |
4 ms |
4948 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
n=5 |
2 |
Correct |
4 ms |
4948 KB |
n=100 |
3 |
Correct |
4 ms |
4948 KB |
n=100 |
4 |
Correct |
4 ms |
5028 KB |
n=100 |
5 |
Correct |
4 ms |
5020 KB |
n=100 |
6 |
Correct |
6 ms |
4948 KB |
n=100 |
7 |
Correct |
6 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
4 ms |
5056 KB |
n=100 |
10 |
Correct |
5 ms |
4948 KB |
n=100 |
11 |
Correct |
4 ms |
5024 KB |
n=100 |
12 |
Correct |
5 ms |
4948 KB |
n=100 |
13 |
Correct |
5 ms |
4968 KB |
n=100 |
14 |
Correct |
3 ms |
5024 KB |
n=100 |
15 |
Correct |
3 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
5020 KB |
n=100 |
17 |
Correct |
3 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
3 ms |
4948 KB |
n=100 |
20 |
Correct |
4 ms |
4948 KB |
n=100 |
21 |
Correct |
3 ms |
4948 KB |
n=100 |
22 |
Correct |
3 ms |
4948 KB |
n=100 |
23 |
Correct |
3 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
4 ms |
4948 KB |
n=100 |
26 |
Correct |
3 ms |
4964 KB |
n=12 |
27 |
Correct |
4 ms |
4948 KB |
n=100 |
28 |
Correct |
31 ms |
5076 KB |
n=500 |
29 |
Correct |
31 ms |
5128 KB |
n=500 |
30 |
Correct |
34 ms |
5076 KB |
n=500 |
31 |
Correct |
42 ms |
5088 KB |
n=500 |
32 |
Correct |
58 ms |
5076 KB |
n=500 |
33 |
Correct |
36 ms |
5076 KB |
n=500 |
34 |
Correct |
35 ms |
5076 KB |
n=500 |
35 |
Correct |
32 ms |
5076 KB |
n=500 |
36 |
Correct |
600 ms |
5088 KB |
n=500 |
37 |
Correct |
604 ms |
5076 KB |
n=500 |
38 |
Correct |
577 ms |
5080 KB |
n=500 |
39 |
Correct |
48 ms |
5076 KB |
n=500 |
40 |
Correct |
46 ms |
5084 KB |
n=500 |
41 |
Correct |
58 ms |
5072 KB |
n=500 |
42 |
Correct |
285 ms |
5076 KB |
n=500 |
43 |
Correct |
278 ms |
5076 KB |
n=500 |
44 |
Correct |
265 ms |
5076 KB |
n=500 |
45 |
Correct |
37 ms |
5076 KB |
n=500 |
46 |
Correct |
32 ms |
5076 KB |
n=500 |
47 |
Correct |
39 ms |
5100 KB |
n=500 |
48 |
Correct |
37 ms |
5076 KB |
n=500 |
49 |
Correct |
28 ms |
5076 KB |
n=500 |
50 |
Correct |
29 ms |
5076 KB |
n=500 |
51 |
Correct |
43 ms |
5076 KB |
n=500 |
52 |
Correct |
33 ms |
5076 KB |
n=500 |
53 |
Correct |
42 ms |
5076 KB |
n=500 |
54 |
Correct |
105 ms |
5104 KB |
n=500 |
55 |
Correct |
14 ms |
4948 KB |
n=278 |
56 |
Correct |
89 ms |
5076 KB |
n=500 |
57 |
Correct |
90 ms |
5104 KB |
n=500 |
58 |
Correct |
171 ms |
5080 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
n=5 |
2 |
Correct |
4 ms |
4948 KB |
n=100 |
3 |
Correct |
4 ms |
4948 KB |
n=100 |
4 |
Correct |
4 ms |
5028 KB |
n=100 |
5 |
Correct |
4 ms |
5020 KB |
n=100 |
6 |
Correct |
6 ms |
4948 KB |
n=100 |
7 |
Correct |
6 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
4 ms |
5056 KB |
n=100 |
10 |
Correct |
5 ms |
4948 KB |
n=100 |
11 |
Correct |
4 ms |
5024 KB |
n=100 |
12 |
Correct |
5 ms |
4948 KB |
n=100 |
13 |
Correct |
5 ms |
4968 KB |
n=100 |
14 |
Correct |
3 ms |
5024 KB |
n=100 |
15 |
Correct |
3 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
5020 KB |
n=100 |
17 |
Correct |
3 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
3 ms |
4948 KB |
n=100 |
20 |
Correct |
4 ms |
4948 KB |
n=100 |
21 |
Correct |
3 ms |
4948 KB |
n=100 |
22 |
Correct |
3 ms |
4948 KB |
n=100 |
23 |
Correct |
3 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
4 ms |
4948 KB |
n=100 |
26 |
Correct |
3 ms |
4964 KB |
n=12 |
27 |
Correct |
4 ms |
4948 KB |
n=100 |
28 |
Correct |
31 ms |
5076 KB |
n=500 |
29 |
Correct |
31 ms |
5128 KB |
n=500 |
30 |
Correct |
34 ms |
5076 KB |
n=500 |
31 |
Correct |
42 ms |
5088 KB |
n=500 |
32 |
Correct |
58 ms |
5076 KB |
n=500 |
33 |
Correct |
36 ms |
5076 KB |
n=500 |
34 |
Correct |
35 ms |
5076 KB |
n=500 |
35 |
Correct |
32 ms |
5076 KB |
n=500 |
36 |
Correct |
600 ms |
5088 KB |
n=500 |
37 |
Correct |
604 ms |
5076 KB |
n=500 |
38 |
Correct |
577 ms |
5080 KB |
n=500 |
39 |
Correct |
48 ms |
5076 KB |
n=500 |
40 |
Correct |
46 ms |
5084 KB |
n=500 |
41 |
Correct |
58 ms |
5072 KB |
n=500 |
42 |
Correct |
285 ms |
5076 KB |
n=500 |
43 |
Correct |
278 ms |
5076 KB |
n=500 |
44 |
Correct |
265 ms |
5076 KB |
n=500 |
45 |
Correct |
37 ms |
5076 KB |
n=500 |
46 |
Correct |
32 ms |
5076 KB |
n=500 |
47 |
Correct |
39 ms |
5100 KB |
n=500 |
48 |
Correct |
37 ms |
5076 KB |
n=500 |
49 |
Correct |
28 ms |
5076 KB |
n=500 |
50 |
Correct |
29 ms |
5076 KB |
n=500 |
51 |
Correct |
43 ms |
5076 KB |
n=500 |
52 |
Correct |
33 ms |
5076 KB |
n=500 |
53 |
Correct |
42 ms |
5076 KB |
n=500 |
54 |
Correct |
105 ms |
5104 KB |
n=500 |
55 |
Correct |
14 ms |
4948 KB |
n=278 |
56 |
Correct |
89 ms |
5076 KB |
n=500 |
57 |
Correct |
90 ms |
5104 KB |
n=500 |
58 |
Correct |
171 ms |
5080 KB |
n=500 |
59 |
Correct |
2183 ms |
5208 KB |
n=2000 |
60 |
Correct |
1671 ms |
5344 KB |
n=2000 |
61 |
Correct |
2972 ms |
5284 KB |
n=2000 |
62 |
Correct |
2840 ms |
5244 KB |
n=2000 |
63 |
Correct |
2744 ms |
5208 KB |
n=2000 |
64 |
Correct |
3017 ms |
5264 KB |
n=2000 |
65 |
Correct |
2267 ms |
5188 KB |
n=2000 |
66 |
Correct |
3073 ms |
5304 KB |
n=2000 |
67 |
Execution timed out |
4059 ms |
5204 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
n=5 |
2 |
Correct |
4 ms |
4948 KB |
n=100 |
3 |
Correct |
4 ms |
4948 KB |
n=100 |
4 |
Correct |
4 ms |
5028 KB |
n=100 |
5 |
Correct |
4 ms |
5020 KB |
n=100 |
6 |
Correct |
6 ms |
4948 KB |
n=100 |
7 |
Correct |
6 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
4 ms |
5056 KB |
n=100 |
10 |
Correct |
5 ms |
4948 KB |
n=100 |
11 |
Correct |
4 ms |
5024 KB |
n=100 |
12 |
Correct |
5 ms |
4948 KB |
n=100 |
13 |
Correct |
5 ms |
4968 KB |
n=100 |
14 |
Correct |
3 ms |
5024 KB |
n=100 |
15 |
Correct |
3 ms |
4948 KB |
n=100 |
16 |
Correct |
3 ms |
5020 KB |
n=100 |
17 |
Correct |
3 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
3 ms |
4948 KB |
n=100 |
20 |
Correct |
4 ms |
4948 KB |
n=100 |
21 |
Correct |
3 ms |
4948 KB |
n=100 |
22 |
Correct |
3 ms |
4948 KB |
n=100 |
23 |
Correct |
3 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
4 ms |
4948 KB |
n=100 |
26 |
Correct |
3 ms |
4964 KB |
n=12 |
27 |
Correct |
4 ms |
4948 KB |
n=100 |
28 |
Correct |
31 ms |
5076 KB |
n=500 |
29 |
Correct |
31 ms |
5128 KB |
n=500 |
30 |
Correct |
34 ms |
5076 KB |
n=500 |
31 |
Correct |
42 ms |
5088 KB |
n=500 |
32 |
Correct |
58 ms |
5076 KB |
n=500 |
33 |
Correct |
36 ms |
5076 KB |
n=500 |
34 |
Correct |
35 ms |
5076 KB |
n=500 |
35 |
Correct |
32 ms |
5076 KB |
n=500 |
36 |
Correct |
600 ms |
5088 KB |
n=500 |
37 |
Correct |
604 ms |
5076 KB |
n=500 |
38 |
Correct |
577 ms |
5080 KB |
n=500 |
39 |
Correct |
48 ms |
5076 KB |
n=500 |
40 |
Correct |
46 ms |
5084 KB |
n=500 |
41 |
Correct |
58 ms |
5072 KB |
n=500 |
42 |
Correct |
285 ms |
5076 KB |
n=500 |
43 |
Correct |
278 ms |
5076 KB |
n=500 |
44 |
Correct |
265 ms |
5076 KB |
n=500 |
45 |
Correct |
37 ms |
5076 KB |
n=500 |
46 |
Correct |
32 ms |
5076 KB |
n=500 |
47 |
Correct |
39 ms |
5100 KB |
n=500 |
48 |
Correct |
37 ms |
5076 KB |
n=500 |
49 |
Correct |
28 ms |
5076 KB |
n=500 |
50 |
Correct |
29 ms |
5076 KB |
n=500 |
51 |
Correct |
43 ms |
5076 KB |
n=500 |
52 |
Correct |
33 ms |
5076 KB |
n=500 |
53 |
Correct |
42 ms |
5076 KB |
n=500 |
54 |
Correct |
105 ms |
5104 KB |
n=500 |
55 |
Correct |
14 ms |
4948 KB |
n=278 |
56 |
Correct |
89 ms |
5076 KB |
n=500 |
57 |
Correct |
90 ms |
5104 KB |
n=500 |
58 |
Correct |
171 ms |
5080 KB |
n=500 |
59 |
Correct |
2183 ms |
5208 KB |
n=2000 |
60 |
Correct |
1671 ms |
5344 KB |
n=2000 |
61 |
Correct |
2972 ms |
5284 KB |
n=2000 |
62 |
Correct |
2840 ms |
5244 KB |
n=2000 |
63 |
Correct |
2744 ms |
5208 KB |
n=2000 |
64 |
Correct |
3017 ms |
5264 KB |
n=2000 |
65 |
Correct |
2267 ms |
5188 KB |
n=2000 |
66 |
Correct |
3073 ms |
5304 KB |
n=2000 |
67 |
Execution timed out |
4059 ms |
5204 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |