#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int base = 74;
const int mxn = 2e5 + 5;
int n, m, q;
vt<int>adj[mxn + 1];
int dep[mxn + 1], up[mxn + 1][18], a[mxn + 1], tin[mxn + 1], tt = 0, tout[mxn + 1], inf = 1e9;
void dfs(int s, int pre){
tin[s] = ++tt;
for(auto i: adj[s]){
if(i != pre){
dep[i] = dep[s] + 1;
dfs(i, s); up[i][0] = s;
}
}
tout[s] = tt;
}
int lca(int u, int v){
if(dep[u] < dep[v])swap(u, v);
int k = dep[u] - dep[v];
forr(i, 0, 18){
if(k & (1 << i)){
u = up[u][i];
}
}
if(u == v)return(u);
dorr(i, 17, 0){
if(up[u][i] != up[v][i]){
u = up[u][i]; v = up[v][i];
}
}
return(up[u][0]);
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
forr(i, 1, n){
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
for(int i = 1; i <= m; i++)cin >> a[i];
dfs(1, -1);
forr(i, 1, 18){
for(int j = 1; j <= n; j++){
up[j][i] = up[up[j][i - 1]][i - 1];
}
}
while(q--){
int idq; cin >> idq;
if(idq == 1){
int id, x; cin >> id >> x; a[id] = x;
}else{
int l, r, v; cin >> l >> r >> v;
int last = l, mn = inf, mx = -1, valmn = -1, valmx = -1;
bool ok = 0;
for(int i = l; i <= r; i++){
if(tin[a[i]] < tin[v] | tin[a[i]] > tout[v]){
mn = inf; mx = -1; valmn = -1; valmx = -1;
continue;
}else{
if(tin[a[i]] < mn){
mn = tin[a[i]]; valmn = i;
}if(tin[a[i]] > mx){
mx = tin[a[i]]; valmx = i;
}
int cand = lca(a[valmn], a[valmx]);
if(cand == v){
cout << min(valmn, valmx) << " " << max(valmn, valmx) << "\n";
ok = 1;
break;
}
}
}
if(!ok)cout << -1 << " " << -1 << "\n";
}
}
return(0);
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:75:30: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
75 | if(tin[a[i]] < tin[v] | tin[a[i]] > tout[v]){
| ~~~~~~~~~~^~~~~~~~
treearray.cpp:72:17: warning: unused variable 'last' [-Wunused-variable]
72 | int last = l, mn = inf, mx = -1, valmn = -1, valmx = -1;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
3 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
3 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
2 ms |
4996 KB |
n=100 |
11 |
Correct |
3 ms |
4948 KB |
n=100 |
12 |
Correct |
3 ms |
4948 KB |
n=100 |
13 |
Correct |
2 ms |
5040 KB |
n=100 |
14 |
Correct |
3 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
2 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
3 ms |
4980 KB |
n=100 |
21 |
Correct |
3 ms |
5076 KB |
n=100 |
22 |
Correct |
4 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
5028 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
3 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
3 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
2 ms |
4996 KB |
n=100 |
11 |
Correct |
3 ms |
4948 KB |
n=100 |
12 |
Correct |
3 ms |
4948 KB |
n=100 |
13 |
Correct |
2 ms |
5040 KB |
n=100 |
14 |
Correct |
3 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
2 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
3 ms |
4980 KB |
n=100 |
21 |
Correct |
3 ms |
5076 KB |
n=100 |
22 |
Correct |
4 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
5028 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
28 |
Correct |
2 ms |
5076 KB |
n=500 |
29 |
Correct |
3 ms |
5076 KB |
n=500 |
30 |
Correct |
3 ms |
5076 KB |
n=500 |
31 |
Correct |
3 ms |
5076 KB |
n=500 |
32 |
Correct |
2 ms |
5076 KB |
n=500 |
33 |
Correct |
3 ms |
5076 KB |
n=500 |
34 |
Correct |
2 ms |
5076 KB |
n=500 |
35 |
Correct |
3 ms |
5076 KB |
n=500 |
36 |
Correct |
3 ms |
5076 KB |
n=500 |
37 |
Correct |
3 ms |
5076 KB |
n=500 |
38 |
Correct |
4 ms |
5032 KB |
n=500 |
39 |
Correct |
3 ms |
5076 KB |
n=500 |
40 |
Correct |
3 ms |
5076 KB |
n=500 |
41 |
Correct |
3 ms |
5076 KB |
n=500 |
42 |
Correct |
3 ms |
5036 KB |
n=500 |
43 |
Correct |
3 ms |
5032 KB |
n=500 |
44 |
Correct |
3 ms |
5076 KB |
n=500 |
45 |
Correct |
3 ms |
5032 KB |
n=500 |
46 |
Correct |
3 ms |
5076 KB |
n=500 |
47 |
Correct |
4 ms |
5076 KB |
n=500 |
48 |
Correct |
4 ms |
5076 KB |
n=500 |
49 |
Correct |
3 ms |
5032 KB |
n=500 |
50 |
Correct |
2 ms |
5076 KB |
n=500 |
51 |
Correct |
3 ms |
5076 KB |
n=500 |
52 |
Correct |
3 ms |
5032 KB |
n=500 |
53 |
Correct |
3 ms |
5036 KB |
n=500 |
54 |
Correct |
3 ms |
5076 KB |
n=500 |
55 |
Correct |
2 ms |
5076 KB |
n=278 |
56 |
Correct |
4 ms |
5076 KB |
n=500 |
57 |
Correct |
4 ms |
5036 KB |
n=500 |
58 |
Correct |
3 ms |
5076 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
3 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
3 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
2 ms |
4996 KB |
n=100 |
11 |
Correct |
3 ms |
4948 KB |
n=100 |
12 |
Correct |
3 ms |
4948 KB |
n=100 |
13 |
Correct |
2 ms |
5040 KB |
n=100 |
14 |
Correct |
3 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
2 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
3 ms |
4980 KB |
n=100 |
21 |
Correct |
3 ms |
5076 KB |
n=100 |
22 |
Correct |
4 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
5028 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
28 |
Correct |
2 ms |
5076 KB |
n=500 |
29 |
Correct |
3 ms |
5076 KB |
n=500 |
30 |
Correct |
3 ms |
5076 KB |
n=500 |
31 |
Correct |
3 ms |
5076 KB |
n=500 |
32 |
Correct |
2 ms |
5076 KB |
n=500 |
33 |
Correct |
3 ms |
5076 KB |
n=500 |
34 |
Correct |
2 ms |
5076 KB |
n=500 |
35 |
Correct |
3 ms |
5076 KB |
n=500 |
36 |
Correct |
3 ms |
5076 KB |
n=500 |
37 |
Correct |
3 ms |
5076 KB |
n=500 |
38 |
Correct |
4 ms |
5032 KB |
n=500 |
39 |
Correct |
3 ms |
5076 KB |
n=500 |
40 |
Correct |
3 ms |
5076 KB |
n=500 |
41 |
Correct |
3 ms |
5076 KB |
n=500 |
42 |
Correct |
3 ms |
5036 KB |
n=500 |
43 |
Correct |
3 ms |
5032 KB |
n=500 |
44 |
Correct |
3 ms |
5076 KB |
n=500 |
45 |
Correct |
3 ms |
5032 KB |
n=500 |
46 |
Correct |
3 ms |
5076 KB |
n=500 |
47 |
Correct |
4 ms |
5076 KB |
n=500 |
48 |
Correct |
4 ms |
5076 KB |
n=500 |
49 |
Correct |
3 ms |
5032 KB |
n=500 |
50 |
Correct |
2 ms |
5076 KB |
n=500 |
51 |
Correct |
3 ms |
5076 KB |
n=500 |
52 |
Correct |
3 ms |
5032 KB |
n=500 |
53 |
Correct |
3 ms |
5036 KB |
n=500 |
54 |
Correct |
3 ms |
5076 KB |
n=500 |
55 |
Correct |
2 ms |
5076 KB |
n=278 |
56 |
Correct |
4 ms |
5076 KB |
n=500 |
57 |
Correct |
4 ms |
5036 KB |
n=500 |
58 |
Correct |
3 ms |
5076 KB |
n=500 |
59 |
Correct |
4 ms |
5332 KB |
n=2000 |
60 |
Correct |
13 ms |
5408 KB |
n=2000 |
61 |
Correct |
13 ms |
5332 KB |
n=2000 |
62 |
Correct |
10 ms |
5296 KB |
n=2000 |
63 |
Correct |
4 ms |
5332 KB |
n=2000 |
64 |
Correct |
13 ms |
5364 KB |
n=2000 |
65 |
Correct |
3 ms |
5332 KB |
n=2000 |
66 |
Correct |
13 ms |
5332 KB |
n=2000 |
67 |
Correct |
4 ms |
5292 KB |
n=2000 |
68 |
Correct |
13 ms |
5332 KB |
n=2000 |
69 |
Correct |
15 ms |
5356 KB |
n=2000 |
70 |
Correct |
18 ms |
5352 KB |
n=2000 |
71 |
Correct |
16 ms |
5332 KB |
n=2000 |
72 |
Correct |
9 ms |
5344 KB |
n=2000 |
73 |
Correct |
10 ms |
5332 KB |
n=2000 |
74 |
Correct |
4 ms |
5296 KB |
n=1844 |
75 |
Correct |
12 ms |
5332 KB |
n=2000 |
76 |
Correct |
13 ms |
5340 KB |
n=2000 |
77 |
Correct |
12 ms |
5336 KB |
n=2000 |
78 |
Correct |
13 ms |
5332 KB |
n=2000 |
79 |
Correct |
3 ms |
5292 KB |
n=2000 |
80 |
Correct |
12 ms |
5372 KB |
n=2000 |
81 |
Correct |
12 ms |
5364 KB |
n=2000 |
82 |
Correct |
3 ms |
5332 KB |
n=2000 |
83 |
Correct |
12 ms |
5292 KB |
n=2000 |
84 |
Correct |
5 ms |
5292 KB |
n=2000 |
85 |
Correct |
13 ms |
5332 KB |
n=2000 |
86 |
Correct |
12 ms |
5288 KB |
n=2000 |
87 |
Correct |
5 ms |
5332 KB |
n=2000 |
88 |
Correct |
32 ms |
5332 KB |
n=2000 |
89 |
Correct |
36 ms |
5384 KB |
n=2000 |
90 |
Correct |
18 ms |
5292 KB |
n=2000 |
91 |
Correct |
6 ms |
5332 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
n=5 |
2 |
Correct |
2 ms |
4948 KB |
n=100 |
3 |
Correct |
3 ms |
4948 KB |
n=100 |
4 |
Correct |
2 ms |
4948 KB |
n=100 |
5 |
Correct |
3 ms |
4948 KB |
n=100 |
6 |
Correct |
2 ms |
4948 KB |
n=100 |
7 |
Correct |
2 ms |
4948 KB |
n=100 |
8 |
Correct |
3 ms |
4948 KB |
n=100 |
9 |
Correct |
2 ms |
4948 KB |
n=100 |
10 |
Correct |
2 ms |
4996 KB |
n=100 |
11 |
Correct |
3 ms |
4948 KB |
n=100 |
12 |
Correct |
3 ms |
4948 KB |
n=100 |
13 |
Correct |
2 ms |
5040 KB |
n=100 |
14 |
Correct |
3 ms |
4948 KB |
n=100 |
15 |
Correct |
2 ms |
4948 KB |
n=100 |
16 |
Correct |
2 ms |
4948 KB |
n=100 |
17 |
Correct |
2 ms |
4948 KB |
n=100 |
18 |
Correct |
3 ms |
4948 KB |
n=100 |
19 |
Correct |
2 ms |
4948 KB |
n=100 |
20 |
Correct |
3 ms |
4980 KB |
n=100 |
21 |
Correct |
3 ms |
5076 KB |
n=100 |
22 |
Correct |
4 ms |
4948 KB |
n=100 |
23 |
Correct |
2 ms |
4948 KB |
n=100 |
24 |
Correct |
3 ms |
4948 KB |
n=100 |
25 |
Correct |
3 ms |
5028 KB |
n=100 |
26 |
Correct |
2 ms |
4948 KB |
n=12 |
27 |
Correct |
2 ms |
4948 KB |
n=100 |
28 |
Correct |
2 ms |
5076 KB |
n=500 |
29 |
Correct |
3 ms |
5076 KB |
n=500 |
30 |
Correct |
3 ms |
5076 KB |
n=500 |
31 |
Correct |
3 ms |
5076 KB |
n=500 |
32 |
Correct |
2 ms |
5076 KB |
n=500 |
33 |
Correct |
3 ms |
5076 KB |
n=500 |
34 |
Correct |
2 ms |
5076 KB |
n=500 |
35 |
Correct |
3 ms |
5076 KB |
n=500 |
36 |
Correct |
3 ms |
5076 KB |
n=500 |
37 |
Correct |
3 ms |
5076 KB |
n=500 |
38 |
Correct |
4 ms |
5032 KB |
n=500 |
39 |
Correct |
3 ms |
5076 KB |
n=500 |
40 |
Correct |
3 ms |
5076 KB |
n=500 |
41 |
Correct |
3 ms |
5076 KB |
n=500 |
42 |
Correct |
3 ms |
5036 KB |
n=500 |
43 |
Correct |
3 ms |
5032 KB |
n=500 |
44 |
Correct |
3 ms |
5076 KB |
n=500 |
45 |
Correct |
3 ms |
5032 KB |
n=500 |
46 |
Correct |
3 ms |
5076 KB |
n=500 |
47 |
Correct |
4 ms |
5076 KB |
n=500 |
48 |
Correct |
4 ms |
5076 KB |
n=500 |
49 |
Correct |
3 ms |
5032 KB |
n=500 |
50 |
Correct |
2 ms |
5076 KB |
n=500 |
51 |
Correct |
3 ms |
5076 KB |
n=500 |
52 |
Correct |
3 ms |
5032 KB |
n=500 |
53 |
Correct |
3 ms |
5036 KB |
n=500 |
54 |
Correct |
3 ms |
5076 KB |
n=500 |
55 |
Correct |
2 ms |
5076 KB |
n=278 |
56 |
Correct |
4 ms |
5076 KB |
n=500 |
57 |
Correct |
4 ms |
5036 KB |
n=500 |
58 |
Correct |
3 ms |
5076 KB |
n=500 |
59 |
Correct |
4 ms |
5332 KB |
n=2000 |
60 |
Correct |
13 ms |
5408 KB |
n=2000 |
61 |
Correct |
13 ms |
5332 KB |
n=2000 |
62 |
Correct |
10 ms |
5296 KB |
n=2000 |
63 |
Correct |
4 ms |
5332 KB |
n=2000 |
64 |
Correct |
13 ms |
5364 KB |
n=2000 |
65 |
Correct |
3 ms |
5332 KB |
n=2000 |
66 |
Correct |
13 ms |
5332 KB |
n=2000 |
67 |
Correct |
4 ms |
5292 KB |
n=2000 |
68 |
Correct |
13 ms |
5332 KB |
n=2000 |
69 |
Correct |
15 ms |
5356 KB |
n=2000 |
70 |
Correct |
18 ms |
5352 KB |
n=2000 |
71 |
Correct |
16 ms |
5332 KB |
n=2000 |
72 |
Correct |
9 ms |
5344 KB |
n=2000 |
73 |
Correct |
10 ms |
5332 KB |
n=2000 |
74 |
Correct |
4 ms |
5296 KB |
n=1844 |
75 |
Correct |
12 ms |
5332 KB |
n=2000 |
76 |
Correct |
13 ms |
5340 KB |
n=2000 |
77 |
Correct |
12 ms |
5336 KB |
n=2000 |
78 |
Correct |
13 ms |
5332 KB |
n=2000 |
79 |
Correct |
3 ms |
5292 KB |
n=2000 |
80 |
Correct |
12 ms |
5372 KB |
n=2000 |
81 |
Correct |
12 ms |
5364 KB |
n=2000 |
82 |
Correct |
3 ms |
5332 KB |
n=2000 |
83 |
Correct |
12 ms |
5292 KB |
n=2000 |
84 |
Correct |
5 ms |
5292 KB |
n=2000 |
85 |
Correct |
13 ms |
5332 KB |
n=2000 |
86 |
Correct |
12 ms |
5288 KB |
n=2000 |
87 |
Correct |
5 ms |
5332 KB |
n=2000 |
88 |
Correct |
32 ms |
5332 KB |
n=2000 |
89 |
Correct |
36 ms |
5384 KB |
n=2000 |
90 |
Correct |
18 ms |
5292 KB |
n=2000 |
91 |
Correct |
6 ms |
5332 KB |
n=2000 |
92 |
Correct |
180 ms |
36904 KB |
n=200000 |
93 |
Execution timed out |
4037 ms |
36156 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |