#include <bits/stdc++.h>
#define pb push_back
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
//#define int long long
#define pii pair < int, int >
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int lg;
int n, m, q, tin[N], tout[N], sz, up[N][20], a[N];
vector < int > g[N];
void dfs(int v, int pr) {
tin[v] = ++sz;
up[v][0] = pr;
for(int i = 1; i < lg; i++) {
up[v][i] = up[up[v][i - 1]][i - 1];
}
for(int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if(to != pr) {
dfs(to, v);
}
}
tout[v] = ++sz;
}
bool upper(int x, int y) {
return tin[x] <= tin[y] && tout[x] >= tout[y];
}
int lca(int x, int y) {
if(upper(x, y)) return x;
if(upper(y, x)) return y;
for(int i = lg - 1; i >= 0; i--) {
if(up[x][i] == 0) continue;
if(!upper(up[x][i], y)) {
x = up[x][i];
}
}
return up[x][0];
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
while((1 << lg) <= n) {
lg++;
}
for(int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
dfs(1, 1);
for(int i = 1; i <= m; i++) {
cin >> a[i];
}
while(q--) {
int tp, pos, l, r, v;
cin >> tp;
if(tp % 2) {
cin >> pos >> v;
a[pos] = v;
} else {
cin >> l >> r >> v;
bool ok = 1;
int lc, lf = -1, rf = -1;
for(int i = l; i <= r; i++) {
if(upper(v, a[i])) {
if(ok) {
ok = 0;
lc = a[i];
lf = i;
rf = i;
} else {
lc = lca(lc, a[i]);
rf++;
}
} else {
ok = 1;
lf = -1;
rf = -1;
}
if(lc == v) break;
}
if(lc != v) {
lf = rf = -1;
}
cout << lf << " " << rf << endl;
}
}
}
Compilation message
treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = 0; i < g[v].size(); i++) {
| ~~^~~~~~~~~~~~~
treearray.cpp: At global scope:
treearray.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main() {
| ^~~~
treearray.cpp: In function 'int main()':
treearray.cpp:95:17: warning: 'lc' may be used uninitialized in this function [-Wmaybe-uninitialized]
95 | if(lc == v) break;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
4 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
3 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
3 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Incorrect |
3 ms |
4940 KB |
Jury has the answer but participant has not |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
4 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
3 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
3 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Incorrect |
3 ms |
4940 KB |
Jury has the answer but participant has not |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
4 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
3 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
3 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Incorrect |
3 ms |
4940 KB |
Jury has the answer but participant has not |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4940 KB |
n=5 |
2 |
Correct |
3 ms |
4940 KB |
n=100 |
3 |
Correct |
3 ms |
4940 KB |
n=100 |
4 |
Correct |
4 ms |
4940 KB |
n=100 |
5 |
Correct |
3 ms |
4940 KB |
n=100 |
6 |
Correct |
3 ms |
4940 KB |
n=100 |
7 |
Correct |
3 ms |
4940 KB |
n=100 |
8 |
Correct |
3 ms |
4940 KB |
n=100 |
9 |
Correct |
3 ms |
4940 KB |
n=100 |
10 |
Correct |
3 ms |
4940 KB |
n=100 |
11 |
Correct |
3 ms |
4940 KB |
n=100 |
12 |
Incorrect |
3 ms |
4940 KB |
Jury has the answer but participant has not |
13 |
Halted |
0 ms |
0 KB |
- |