/*input
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 1 3 1
2 3 4 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
int raise(int a,int n,int m = MOD){
if(n == 0)return 1;
if(n == 1)return a;
int x = 1;
x *= raise(a,n/2,m);
x %= m;
x *= x;
x %= m;
if(n%2)x*= a;
x %= m;
return x;
}
int floor1(int n,int k){
if(n%k == 0 || n >= 0)return n/k;
return (n/k)-1;
}
int ceil1(int n,int k){
return floor1(n+k-1,k);
}
const int LG = 18;
const int N = 2e5+1;
vector<int> adj[N];
int n,m,q;
int pre[N][LG];
int a[N];
int dist[N];
void dfs(int u,int p){
pre[u][0] = p;
RE(i,LG-1){
pre[u][i] = pre[pre[u][i-1]][i-1];
}
for(int v:adj[u]){
if(v == p)continue;
dist[v] = dist[u]+1;
dfs(v,u);
}
}
int lca(int u,int v){
if(dist[v] > dist[u])swap(u,v);
for(int i = LG-1;i > -1;i--){
if(dist[pre[u][i]] >= dist[v]){
u = pre[u][i];
}
}
for(int i = LG-1;i > -1;i--){
if(pre[u][i] != pre[v][i]){
u = pre[u][i];
v = pre[v][i];
}
}
if(u == v)return u;
return pre[u][0];
}
void solve(){
cin >> n >> m >> q;
RE(i,n-1){
int a,b;cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
dist[1] = 1;
dfs(1,0);
RE(i,m)cin >> a[i];
while(q--){
int ty;cin >> ty;
if(ty == 1){
int ind,ok;cin >> ind >> ok;
a[ind] = ok;
}
else{
int k;
int l,r;cin >> l >> r >> k;
bool f = 0;
for(int i = l;i <= r;i++){
if(a[i] == k){
cout << i << " " << i << endl;
f = 1;
break;
}
if(i < r and lca(a[i],a[i+1]) == k){
cout << i << " " << i+1 << endl;
f = 1;
break;
}
}
if(!f)cout << "-1 -1\n";
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(".in","r",stdin);freopen(".out","w",stdout);
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
n=5 |
2 |
Correct |
7 ms |
5116 KB |
n=100 |
3 |
Correct |
6 ms |
5112 KB |
n=100 |
4 |
Correct |
6 ms |
5112 KB |
n=100 |
5 |
Correct |
7 ms |
5116 KB |
n=100 |
6 |
Correct |
8 ms |
5112 KB |
n=100 |
7 |
Correct |
8 ms |
5112 KB |
n=100 |
8 |
Correct |
7 ms |
5112 KB |
n=100 |
9 |
Correct |
7 ms |
5112 KB |
n=100 |
10 |
Correct |
7 ms |
5064 KB |
n=100 |
11 |
Correct |
7 ms |
5112 KB |
n=100 |
12 |
Correct |
6 ms |
5112 KB |
n=100 |
13 |
Correct |
6 ms |
5112 KB |
n=100 |
14 |
Correct |
8 ms |
5112 KB |
n=100 |
15 |
Correct |
6 ms |
5112 KB |
n=100 |
16 |
Correct |
6 ms |
5112 KB |
n=100 |
17 |
Correct |
7 ms |
5112 KB |
n=100 |
18 |
Correct |
7 ms |
5112 KB |
n=100 |
19 |
Correct |
6 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
5112 KB |
n=100 |
21 |
Correct |
6 ms |
5112 KB |
n=100 |
22 |
Correct |
6 ms |
5112 KB |
n=100 |
23 |
Correct |
6 ms |
5112 KB |
n=100 |
24 |
Correct |
7 ms |
5112 KB |
n=100 |
25 |
Correct |
7 ms |
5112 KB |
n=100 |
26 |
Correct |
7 ms |
4984 KB |
n=12 |
27 |
Correct |
7 ms |
5112 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
n=5 |
2 |
Correct |
7 ms |
5116 KB |
n=100 |
3 |
Correct |
6 ms |
5112 KB |
n=100 |
4 |
Correct |
6 ms |
5112 KB |
n=100 |
5 |
Correct |
7 ms |
5116 KB |
n=100 |
6 |
Correct |
8 ms |
5112 KB |
n=100 |
7 |
Correct |
8 ms |
5112 KB |
n=100 |
8 |
Correct |
7 ms |
5112 KB |
n=100 |
9 |
Correct |
7 ms |
5112 KB |
n=100 |
10 |
Correct |
7 ms |
5064 KB |
n=100 |
11 |
Correct |
7 ms |
5112 KB |
n=100 |
12 |
Correct |
6 ms |
5112 KB |
n=100 |
13 |
Correct |
6 ms |
5112 KB |
n=100 |
14 |
Correct |
8 ms |
5112 KB |
n=100 |
15 |
Correct |
6 ms |
5112 KB |
n=100 |
16 |
Correct |
6 ms |
5112 KB |
n=100 |
17 |
Correct |
7 ms |
5112 KB |
n=100 |
18 |
Correct |
7 ms |
5112 KB |
n=100 |
19 |
Correct |
6 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
5112 KB |
n=100 |
21 |
Correct |
6 ms |
5112 KB |
n=100 |
22 |
Correct |
6 ms |
5112 KB |
n=100 |
23 |
Correct |
6 ms |
5112 KB |
n=100 |
24 |
Correct |
7 ms |
5112 KB |
n=100 |
25 |
Correct |
7 ms |
5112 KB |
n=100 |
26 |
Correct |
7 ms |
4984 KB |
n=12 |
27 |
Correct |
7 ms |
5112 KB |
n=100 |
28 |
Correct |
8 ms |
5112 KB |
n=500 |
29 |
Correct |
12 ms |
5240 KB |
n=500 |
30 |
Correct |
11 ms |
5244 KB |
n=500 |
31 |
Correct |
12 ms |
5240 KB |
n=500 |
32 |
Correct |
8 ms |
5240 KB |
n=500 |
33 |
Correct |
11 ms |
5240 KB |
n=500 |
34 |
Correct |
7 ms |
5240 KB |
n=500 |
35 |
Correct |
11 ms |
5240 KB |
n=500 |
36 |
Correct |
32 ms |
5084 KB |
n=500 |
37 |
Correct |
31 ms |
5112 KB |
n=500 |
38 |
Correct |
32 ms |
5112 KB |
n=500 |
39 |
Correct |
18 ms |
5240 KB |
n=500 |
40 |
Correct |
18 ms |
5240 KB |
n=500 |
41 |
Correct |
18 ms |
5116 KB |
n=500 |
42 |
Correct |
19 ms |
5112 KB |
n=500 |
43 |
Correct |
22 ms |
5112 KB |
n=500 |
44 |
Correct |
18 ms |
5240 KB |
n=500 |
45 |
Correct |
8 ms |
5240 KB |
n=500 |
46 |
Correct |
11 ms |
5112 KB |
n=500 |
47 |
Correct |
19 ms |
5240 KB |
n=500 |
48 |
Correct |
7 ms |
5112 KB |
n=500 |
49 |
Correct |
11 ms |
5112 KB |
n=500 |
50 |
Correct |
13 ms |
5112 KB |
n=500 |
51 |
Correct |
15 ms |
5240 KB |
n=500 |
52 |
Correct |
15 ms |
5112 KB |
n=500 |
53 |
Correct |
14 ms |
5112 KB |
n=500 |
54 |
Correct |
19 ms |
5240 KB |
n=500 |
55 |
Correct |
7 ms |
5112 KB |
n=278 |
56 |
Correct |
27 ms |
5240 KB |
n=500 |
57 |
Correct |
27 ms |
5112 KB |
n=500 |
58 |
Correct |
25 ms |
5112 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
n=5 |
2 |
Correct |
7 ms |
5116 KB |
n=100 |
3 |
Correct |
6 ms |
5112 KB |
n=100 |
4 |
Correct |
6 ms |
5112 KB |
n=100 |
5 |
Correct |
7 ms |
5116 KB |
n=100 |
6 |
Correct |
8 ms |
5112 KB |
n=100 |
7 |
Correct |
8 ms |
5112 KB |
n=100 |
8 |
Correct |
7 ms |
5112 KB |
n=100 |
9 |
Correct |
7 ms |
5112 KB |
n=100 |
10 |
Correct |
7 ms |
5064 KB |
n=100 |
11 |
Correct |
7 ms |
5112 KB |
n=100 |
12 |
Correct |
6 ms |
5112 KB |
n=100 |
13 |
Correct |
6 ms |
5112 KB |
n=100 |
14 |
Correct |
8 ms |
5112 KB |
n=100 |
15 |
Correct |
6 ms |
5112 KB |
n=100 |
16 |
Correct |
6 ms |
5112 KB |
n=100 |
17 |
Correct |
7 ms |
5112 KB |
n=100 |
18 |
Correct |
7 ms |
5112 KB |
n=100 |
19 |
Correct |
6 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
5112 KB |
n=100 |
21 |
Correct |
6 ms |
5112 KB |
n=100 |
22 |
Correct |
6 ms |
5112 KB |
n=100 |
23 |
Correct |
6 ms |
5112 KB |
n=100 |
24 |
Correct |
7 ms |
5112 KB |
n=100 |
25 |
Correct |
7 ms |
5112 KB |
n=100 |
26 |
Correct |
7 ms |
4984 KB |
n=12 |
27 |
Correct |
7 ms |
5112 KB |
n=100 |
28 |
Correct |
8 ms |
5112 KB |
n=500 |
29 |
Correct |
12 ms |
5240 KB |
n=500 |
30 |
Correct |
11 ms |
5244 KB |
n=500 |
31 |
Correct |
12 ms |
5240 KB |
n=500 |
32 |
Correct |
8 ms |
5240 KB |
n=500 |
33 |
Correct |
11 ms |
5240 KB |
n=500 |
34 |
Correct |
7 ms |
5240 KB |
n=500 |
35 |
Correct |
11 ms |
5240 KB |
n=500 |
36 |
Correct |
32 ms |
5084 KB |
n=500 |
37 |
Correct |
31 ms |
5112 KB |
n=500 |
38 |
Correct |
32 ms |
5112 KB |
n=500 |
39 |
Correct |
18 ms |
5240 KB |
n=500 |
40 |
Correct |
18 ms |
5240 KB |
n=500 |
41 |
Correct |
18 ms |
5116 KB |
n=500 |
42 |
Correct |
19 ms |
5112 KB |
n=500 |
43 |
Correct |
22 ms |
5112 KB |
n=500 |
44 |
Correct |
18 ms |
5240 KB |
n=500 |
45 |
Correct |
8 ms |
5240 KB |
n=500 |
46 |
Correct |
11 ms |
5112 KB |
n=500 |
47 |
Correct |
19 ms |
5240 KB |
n=500 |
48 |
Correct |
7 ms |
5112 KB |
n=500 |
49 |
Correct |
11 ms |
5112 KB |
n=500 |
50 |
Correct |
13 ms |
5112 KB |
n=500 |
51 |
Correct |
15 ms |
5240 KB |
n=500 |
52 |
Correct |
15 ms |
5112 KB |
n=500 |
53 |
Correct |
14 ms |
5112 KB |
n=500 |
54 |
Correct |
19 ms |
5240 KB |
n=500 |
55 |
Correct |
7 ms |
5112 KB |
n=278 |
56 |
Correct |
27 ms |
5240 KB |
n=500 |
57 |
Correct |
27 ms |
5112 KB |
n=500 |
58 |
Correct |
25 ms |
5112 KB |
n=500 |
59 |
Correct |
10 ms |
5496 KB |
n=2000 |
60 |
Correct |
85 ms |
5624 KB |
n=2000 |
61 |
Correct |
80 ms |
5752 KB |
n=2000 |
62 |
Correct |
55 ms |
5496 KB |
n=2000 |
63 |
Correct |
11 ms |
5500 KB |
n=2000 |
64 |
Correct |
78 ms |
5568 KB |
n=2000 |
65 |
Correct |
11 ms |
5496 KB |
n=2000 |
66 |
Correct |
90 ms |
5624 KB |
n=2000 |
67 |
Correct |
14 ms |
5500 KB |
n=2000 |
68 |
Correct |
83 ms |
5624 KB |
n=2000 |
69 |
Correct |
401 ms |
5752 KB |
n=2000 |
70 |
Correct |
421 ms |
5752 KB |
n=2000 |
71 |
Correct |
415 ms |
5496 KB |
n=2000 |
72 |
Correct |
201 ms |
5624 KB |
n=2000 |
73 |
Correct |
202 ms |
5624 KB |
n=2000 |
74 |
Correct |
11 ms |
5496 KB |
n=1844 |
75 |
Correct |
203 ms |
5596 KB |
n=2000 |
76 |
Correct |
204 ms |
5496 KB |
n=2000 |
77 |
Correct |
207 ms |
5496 KB |
n=2000 |
78 |
Correct |
219 ms |
5496 KB |
n=2000 |
79 |
Correct |
10 ms |
5496 KB |
n=2000 |
80 |
Correct |
75 ms |
5624 KB |
n=2000 |
81 |
Correct |
66 ms |
5624 KB |
n=2000 |
82 |
Correct |
10 ms |
5496 KB |
n=2000 |
83 |
Correct |
84 ms |
5496 KB |
n=2000 |
84 |
Correct |
116 ms |
5496 KB |
n=2000 |
85 |
Correct |
124 ms |
5496 KB |
n=2000 |
86 |
Correct |
129 ms |
5496 KB |
n=2000 |
87 |
Correct |
117 ms |
5496 KB |
n=2000 |
88 |
Correct |
460 ms |
5656 KB |
n=2000 |
89 |
Correct |
435 ms |
5752 KB |
n=2000 |
90 |
Correct |
227 ms |
5624 KB |
n=2000 |
91 |
Correct |
313 ms |
5624 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5240 KB |
n=5 |
2 |
Correct |
7 ms |
5116 KB |
n=100 |
3 |
Correct |
6 ms |
5112 KB |
n=100 |
4 |
Correct |
6 ms |
5112 KB |
n=100 |
5 |
Correct |
7 ms |
5116 KB |
n=100 |
6 |
Correct |
8 ms |
5112 KB |
n=100 |
7 |
Correct |
8 ms |
5112 KB |
n=100 |
8 |
Correct |
7 ms |
5112 KB |
n=100 |
9 |
Correct |
7 ms |
5112 KB |
n=100 |
10 |
Correct |
7 ms |
5064 KB |
n=100 |
11 |
Correct |
7 ms |
5112 KB |
n=100 |
12 |
Correct |
6 ms |
5112 KB |
n=100 |
13 |
Correct |
6 ms |
5112 KB |
n=100 |
14 |
Correct |
8 ms |
5112 KB |
n=100 |
15 |
Correct |
6 ms |
5112 KB |
n=100 |
16 |
Correct |
6 ms |
5112 KB |
n=100 |
17 |
Correct |
7 ms |
5112 KB |
n=100 |
18 |
Correct |
7 ms |
5112 KB |
n=100 |
19 |
Correct |
6 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
5112 KB |
n=100 |
21 |
Correct |
6 ms |
5112 KB |
n=100 |
22 |
Correct |
6 ms |
5112 KB |
n=100 |
23 |
Correct |
6 ms |
5112 KB |
n=100 |
24 |
Correct |
7 ms |
5112 KB |
n=100 |
25 |
Correct |
7 ms |
5112 KB |
n=100 |
26 |
Correct |
7 ms |
4984 KB |
n=12 |
27 |
Correct |
7 ms |
5112 KB |
n=100 |
28 |
Correct |
8 ms |
5112 KB |
n=500 |
29 |
Correct |
12 ms |
5240 KB |
n=500 |
30 |
Correct |
11 ms |
5244 KB |
n=500 |
31 |
Correct |
12 ms |
5240 KB |
n=500 |
32 |
Correct |
8 ms |
5240 KB |
n=500 |
33 |
Correct |
11 ms |
5240 KB |
n=500 |
34 |
Correct |
7 ms |
5240 KB |
n=500 |
35 |
Correct |
11 ms |
5240 KB |
n=500 |
36 |
Correct |
32 ms |
5084 KB |
n=500 |
37 |
Correct |
31 ms |
5112 KB |
n=500 |
38 |
Correct |
32 ms |
5112 KB |
n=500 |
39 |
Correct |
18 ms |
5240 KB |
n=500 |
40 |
Correct |
18 ms |
5240 KB |
n=500 |
41 |
Correct |
18 ms |
5116 KB |
n=500 |
42 |
Correct |
19 ms |
5112 KB |
n=500 |
43 |
Correct |
22 ms |
5112 KB |
n=500 |
44 |
Correct |
18 ms |
5240 KB |
n=500 |
45 |
Correct |
8 ms |
5240 KB |
n=500 |
46 |
Correct |
11 ms |
5112 KB |
n=500 |
47 |
Correct |
19 ms |
5240 KB |
n=500 |
48 |
Correct |
7 ms |
5112 KB |
n=500 |
49 |
Correct |
11 ms |
5112 KB |
n=500 |
50 |
Correct |
13 ms |
5112 KB |
n=500 |
51 |
Correct |
15 ms |
5240 KB |
n=500 |
52 |
Correct |
15 ms |
5112 KB |
n=500 |
53 |
Correct |
14 ms |
5112 KB |
n=500 |
54 |
Correct |
19 ms |
5240 KB |
n=500 |
55 |
Correct |
7 ms |
5112 KB |
n=278 |
56 |
Correct |
27 ms |
5240 KB |
n=500 |
57 |
Correct |
27 ms |
5112 KB |
n=500 |
58 |
Correct |
25 ms |
5112 KB |
n=500 |
59 |
Correct |
10 ms |
5496 KB |
n=2000 |
60 |
Correct |
85 ms |
5624 KB |
n=2000 |
61 |
Correct |
80 ms |
5752 KB |
n=2000 |
62 |
Correct |
55 ms |
5496 KB |
n=2000 |
63 |
Correct |
11 ms |
5500 KB |
n=2000 |
64 |
Correct |
78 ms |
5568 KB |
n=2000 |
65 |
Correct |
11 ms |
5496 KB |
n=2000 |
66 |
Correct |
90 ms |
5624 KB |
n=2000 |
67 |
Correct |
14 ms |
5500 KB |
n=2000 |
68 |
Correct |
83 ms |
5624 KB |
n=2000 |
69 |
Correct |
401 ms |
5752 KB |
n=2000 |
70 |
Correct |
421 ms |
5752 KB |
n=2000 |
71 |
Correct |
415 ms |
5496 KB |
n=2000 |
72 |
Correct |
201 ms |
5624 KB |
n=2000 |
73 |
Correct |
202 ms |
5624 KB |
n=2000 |
74 |
Correct |
11 ms |
5496 KB |
n=1844 |
75 |
Correct |
203 ms |
5596 KB |
n=2000 |
76 |
Correct |
204 ms |
5496 KB |
n=2000 |
77 |
Correct |
207 ms |
5496 KB |
n=2000 |
78 |
Correct |
219 ms |
5496 KB |
n=2000 |
79 |
Correct |
10 ms |
5496 KB |
n=2000 |
80 |
Correct |
75 ms |
5624 KB |
n=2000 |
81 |
Correct |
66 ms |
5624 KB |
n=2000 |
82 |
Correct |
10 ms |
5496 KB |
n=2000 |
83 |
Correct |
84 ms |
5496 KB |
n=2000 |
84 |
Correct |
116 ms |
5496 KB |
n=2000 |
85 |
Correct |
124 ms |
5496 KB |
n=2000 |
86 |
Correct |
129 ms |
5496 KB |
n=2000 |
87 |
Correct |
117 ms |
5496 KB |
n=2000 |
88 |
Correct |
460 ms |
5656 KB |
n=2000 |
89 |
Correct |
435 ms |
5752 KB |
n=2000 |
90 |
Correct |
227 ms |
5624 KB |
n=2000 |
91 |
Correct |
313 ms |
5624 KB |
n=2000 |
92 |
Correct |
1644 ms |
52024 KB |
n=200000 |
93 |
Execution timed out |
4011 ms |
52344 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |