#include <bits/stdc++.h>
using namespace std;
#define Task ""
struct __Init__ {
__Init__() {
cin.tie(nullptr)->sync_with_stdio(false);
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout); }
}
} __init__;
using ll = long long;
#ifdef LOCAL
#define debug(x) cerr << "[" #x " = " << x << "]\n";
#else
#define debug(...)
#endif // LOCAL
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// =============================================================================
constexpr int maxN = 2000 + 5;
constexpr int logN = 20;
int n, m, nq;
vector<int> g[maxN];
int a[maxN];
int par[maxN][logN];
int dep[maxN];
int lca[maxN][maxN];
void Dfs(int u) {
for (int v : g[u]) if (v != par[u][0]) {
par[v][0] = u;
dep[v] = dep[u] + 1;
Dfs(v);
}
}
int getLca(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
Repd (i, logN) if ((dep[u] - dep[v]) >> i & 1) {
u = par[u][i];
}
if (u == v) return u;
Repd (i, logN) if (par[u][i] != par[v][i]) {
u = par[u][i];
v = par[v][i];
}
return par[u][0];
}
signed main() {
cin >> n >> m >> nq;
Rep (_, n - 1) {
int u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
For (i, 1, m) cin >> a[i];
Dfs(1);
For (j, 1, logN - 1) {
For (i, 1, n) {
par[i][j] = par[par[i][j - 1]][j - 1];
}
}
For (i, 1, n) {
For (j, i, n) {
lca[i][j] = lca[j][i] = getLca(i, j);
}
}
Rep (_, nq) {
int op; cin >> op;
if (op == 1) {
int p, x; cin >> p >> x;
a[p] = x;
} else {
int l, r, v; cin >> l >> r >> v;
int ansL = -1, ansR = -1;
For (i, l, r) {
int node = a[i];
For (j, i, r) {
node = lca[node][a[j]];
if (node == v) {
ansL = i;
ansR = j;
break;
}
}
if (ansL != -1) break;
}
cout << ansL << ' ' << ansR << '\n';
}
}
}
/*
*/
Compilation message
treearray.cpp: In constructor '__Init__::__Init__()':
treearray.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(Task".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
n=5 |
2 |
Correct |
1 ms |
716 KB |
n=100 |
3 |
Correct |
1 ms |
716 KB |
n=100 |
4 |
Correct |
1 ms |
716 KB |
n=100 |
5 |
Correct |
1 ms |
716 KB |
n=100 |
6 |
Correct |
2 ms |
716 KB |
n=100 |
7 |
Correct |
2 ms |
716 KB |
n=100 |
8 |
Correct |
1 ms |
716 KB |
n=100 |
9 |
Correct |
1 ms |
716 KB |
n=100 |
10 |
Correct |
2 ms |
716 KB |
n=100 |
11 |
Correct |
2 ms |
716 KB |
n=100 |
12 |
Correct |
1 ms |
716 KB |
n=100 |
13 |
Correct |
1 ms |
716 KB |
n=100 |
14 |
Correct |
1 ms |
716 KB |
n=100 |
15 |
Correct |
1 ms |
716 KB |
n=100 |
16 |
Correct |
1 ms |
716 KB |
n=100 |
17 |
Correct |
1 ms |
716 KB |
n=100 |
18 |
Correct |
1 ms |
716 KB |
n=100 |
19 |
Correct |
1 ms |
716 KB |
n=100 |
20 |
Correct |
1 ms |
716 KB |
n=100 |
21 |
Correct |
1 ms |
716 KB |
n=100 |
22 |
Correct |
1 ms |
716 KB |
n=100 |
23 |
Correct |
1 ms |
832 KB |
n=100 |
24 |
Correct |
1 ms |
716 KB |
n=100 |
25 |
Correct |
1 ms |
716 KB |
n=100 |
26 |
Correct |
1 ms |
332 KB |
n=12 |
27 |
Correct |
1 ms |
716 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
n=5 |
2 |
Correct |
1 ms |
716 KB |
n=100 |
3 |
Correct |
1 ms |
716 KB |
n=100 |
4 |
Correct |
1 ms |
716 KB |
n=100 |
5 |
Correct |
1 ms |
716 KB |
n=100 |
6 |
Correct |
2 ms |
716 KB |
n=100 |
7 |
Correct |
2 ms |
716 KB |
n=100 |
8 |
Correct |
1 ms |
716 KB |
n=100 |
9 |
Correct |
1 ms |
716 KB |
n=100 |
10 |
Correct |
2 ms |
716 KB |
n=100 |
11 |
Correct |
2 ms |
716 KB |
n=100 |
12 |
Correct |
1 ms |
716 KB |
n=100 |
13 |
Correct |
1 ms |
716 KB |
n=100 |
14 |
Correct |
1 ms |
716 KB |
n=100 |
15 |
Correct |
1 ms |
716 KB |
n=100 |
16 |
Correct |
1 ms |
716 KB |
n=100 |
17 |
Correct |
1 ms |
716 KB |
n=100 |
18 |
Correct |
1 ms |
716 KB |
n=100 |
19 |
Correct |
1 ms |
716 KB |
n=100 |
20 |
Correct |
1 ms |
716 KB |
n=100 |
21 |
Correct |
1 ms |
716 KB |
n=100 |
22 |
Correct |
1 ms |
716 KB |
n=100 |
23 |
Correct |
1 ms |
832 KB |
n=100 |
24 |
Correct |
1 ms |
716 KB |
n=100 |
25 |
Correct |
1 ms |
716 KB |
n=100 |
26 |
Correct |
1 ms |
332 KB |
n=12 |
27 |
Correct |
1 ms |
716 KB |
n=100 |
28 |
Correct |
10 ms |
3364 KB |
n=500 |
29 |
Correct |
23 ms |
3344 KB |
n=500 |
30 |
Correct |
19 ms |
3376 KB |
n=500 |
31 |
Correct |
21 ms |
3404 KB |
n=500 |
32 |
Correct |
10 ms |
3352 KB |
n=500 |
33 |
Correct |
18 ms |
3420 KB |
n=500 |
34 |
Correct |
10 ms |
3372 KB |
n=500 |
35 |
Correct |
21 ms |
3404 KB |
n=500 |
36 |
Correct |
166 ms |
3396 KB |
n=500 |
37 |
Correct |
172 ms |
3396 KB |
n=500 |
38 |
Correct |
167 ms |
3404 KB |
n=500 |
39 |
Correct |
28 ms |
3420 KB |
n=500 |
40 |
Correct |
27 ms |
3352 KB |
n=500 |
41 |
Correct |
32 ms |
3412 KB |
n=500 |
42 |
Correct |
85 ms |
3400 KB |
n=500 |
43 |
Correct |
83 ms |
3404 KB |
n=500 |
44 |
Correct |
85 ms |
3404 KB |
n=500 |
45 |
Correct |
10 ms |
3404 KB |
n=500 |
46 |
Correct |
24 ms |
3444 KB |
n=500 |
47 |
Correct |
24 ms |
3372 KB |
n=500 |
48 |
Correct |
14 ms |
3404 KB |
n=500 |
49 |
Correct |
21 ms |
3448 KB |
n=500 |
50 |
Correct |
27 ms |
3300 KB |
n=500 |
51 |
Correct |
28 ms |
3424 KB |
n=500 |
52 |
Correct |
34 ms |
3404 KB |
n=500 |
53 |
Correct |
26 ms |
3404 KB |
n=500 |
54 |
Correct |
19 ms |
3400 KB |
n=500 |
55 |
Correct |
6 ms |
1740 KB |
n=278 |
56 |
Correct |
102 ms |
3420 KB |
n=500 |
57 |
Correct |
92 ms |
3404 KB |
n=500 |
58 |
Correct |
69 ms |
3416 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
n=5 |
2 |
Correct |
1 ms |
716 KB |
n=100 |
3 |
Correct |
1 ms |
716 KB |
n=100 |
4 |
Correct |
1 ms |
716 KB |
n=100 |
5 |
Correct |
1 ms |
716 KB |
n=100 |
6 |
Correct |
2 ms |
716 KB |
n=100 |
7 |
Correct |
2 ms |
716 KB |
n=100 |
8 |
Correct |
1 ms |
716 KB |
n=100 |
9 |
Correct |
1 ms |
716 KB |
n=100 |
10 |
Correct |
2 ms |
716 KB |
n=100 |
11 |
Correct |
2 ms |
716 KB |
n=100 |
12 |
Correct |
1 ms |
716 KB |
n=100 |
13 |
Correct |
1 ms |
716 KB |
n=100 |
14 |
Correct |
1 ms |
716 KB |
n=100 |
15 |
Correct |
1 ms |
716 KB |
n=100 |
16 |
Correct |
1 ms |
716 KB |
n=100 |
17 |
Correct |
1 ms |
716 KB |
n=100 |
18 |
Correct |
1 ms |
716 KB |
n=100 |
19 |
Correct |
1 ms |
716 KB |
n=100 |
20 |
Correct |
1 ms |
716 KB |
n=100 |
21 |
Correct |
1 ms |
716 KB |
n=100 |
22 |
Correct |
1 ms |
716 KB |
n=100 |
23 |
Correct |
1 ms |
832 KB |
n=100 |
24 |
Correct |
1 ms |
716 KB |
n=100 |
25 |
Correct |
1 ms |
716 KB |
n=100 |
26 |
Correct |
1 ms |
332 KB |
n=12 |
27 |
Correct |
1 ms |
716 KB |
n=100 |
28 |
Correct |
10 ms |
3364 KB |
n=500 |
29 |
Correct |
23 ms |
3344 KB |
n=500 |
30 |
Correct |
19 ms |
3376 KB |
n=500 |
31 |
Correct |
21 ms |
3404 KB |
n=500 |
32 |
Correct |
10 ms |
3352 KB |
n=500 |
33 |
Correct |
18 ms |
3420 KB |
n=500 |
34 |
Correct |
10 ms |
3372 KB |
n=500 |
35 |
Correct |
21 ms |
3404 KB |
n=500 |
36 |
Correct |
166 ms |
3396 KB |
n=500 |
37 |
Correct |
172 ms |
3396 KB |
n=500 |
38 |
Correct |
167 ms |
3404 KB |
n=500 |
39 |
Correct |
28 ms |
3420 KB |
n=500 |
40 |
Correct |
27 ms |
3352 KB |
n=500 |
41 |
Correct |
32 ms |
3412 KB |
n=500 |
42 |
Correct |
85 ms |
3400 KB |
n=500 |
43 |
Correct |
83 ms |
3404 KB |
n=500 |
44 |
Correct |
85 ms |
3404 KB |
n=500 |
45 |
Correct |
10 ms |
3404 KB |
n=500 |
46 |
Correct |
24 ms |
3444 KB |
n=500 |
47 |
Correct |
24 ms |
3372 KB |
n=500 |
48 |
Correct |
14 ms |
3404 KB |
n=500 |
49 |
Correct |
21 ms |
3448 KB |
n=500 |
50 |
Correct |
27 ms |
3300 KB |
n=500 |
51 |
Correct |
28 ms |
3424 KB |
n=500 |
52 |
Correct |
34 ms |
3404 KB |
n=500 |
53 |
Correct |
26 ms |
3404 KB |
n=500 |
54 |
Correct |
19 ms |
3400 KB |
n=500 |
55 |
Correct |
6 ms |
1740 KB |
n=278 |
56 |
Correct |
102 ms |
3420 KB |
n=500 |
57 |
Correct |
92 ms |
3404 KB |
n=500 |
58 |
Correct |
69 ms |
3416 KB |
n=500 |
59 |
Correct |
158 ms |
16240 KB |
n=2000 |
60 |
Correct |
1051 ms |
16404 KB |
n=2000 |
61 |
Correct |
1004 ms |
16536 KB |
n=2000 |
62 |
Correct |
745 ms |
16400 KB |
n=2000 |
63 |
Correct |
171 ms |
16340 KB |
n=2000 |
64 |
Correct |
891 ms |
16328 KB |
n=2000 |
65 |
Correct |
144 ms |
16336 KB |
n=2000 |
66 |
Correct |
1199 ms |
16512 KB |
n=2000 |
67 |
Correct |
231 ms |
16268 KB |
n=2000 |
68 |
Correct |
919 ms |
16476 KB |
n=2000 |
69 |
Execution timed out |
4018 ms |
16332 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
n=5 |
2 |
Correct |
1 ms |
716 KB |
n=100 |
3 |
Correct |
1 ms |
716 KB |
n=100 |
4 |
Correct |
1 ms |
716 KB |
n=100 |
5 |
Correct |
1 ms |
716 KB |
n=100 |
6 |
Correct |
2 ms |
716 KB |
n=100 |
7 |
Correct |
2 ms |
716 KB |
n=100 |
8 |
Correct |
1 ms |
716 KB |
n=100 |
9 |
Correct |
1 ms |
716 KB |
n=100 |
10 |
Correct |
2 ms |
716 KB |
n=100 |
11 |
Correct |
2 ms |
716 KB |
n=100 |
12 |
Correct |
1 ms |
716 KB |
n=100 |
13 |
Correct |
1 ms |
716 KB |
n=100 |
14 |
Correct |
1 ms |
716 KB |
n=100 |
15 |
Correct |
1 ms |
716 KB |
n=100 |
16 |
Correct |
1 ms |
716 KB |
n=100 |
17 |
Correct |
1 ms |
716 KB |
n=100 |
18 |
Correct |
1 ms |
716 KB |
n=100 |
19 |
Correct |
1 ms |
716 KB |
n=100 |
20 |
Correct |
1 ms |
716 KB |
n=100 |
21 |
Correct |
1 ms |
716 KB |
n=100 |
22 |
Correct |
1 ms |
716 KB |
n=100 |
23 |
Correct |
1 ms |
832 KB |
n=100 |
24 |
Correct |
1 ms |
716 KB |
n=100 |
25 |
Correct |
1 ms |
716 KB |
n=100 |
26 |
Correct |
1 ms |
332 KB |
n=12 |
27 |
Correct |
1 ms |
716 KB |
n=100 |
28 |
Correct |
10 ms |
3364 KB |
n=500 |
29 |
Correct |
23 ms |
3344 KB |
n=500 |
30 |
Correct |
19 ms |
3376 KB |
n=500 |
31 |
Correct |
21 ms |
3404 KB |
n=500 |
32 |
Correct |
10 ms |
3352 KB |
n=500 |
33 |
Correct |
18 ms |
3420 KB |
n=500 |
34 |
Correct |
10 ms |
3372 KB |
n=500 |
35 |
Correct |
21 ms |
3404 KB |
n=500 |
36 |
Correct |
166 ms |
3396 KB |
n=500 |
37 |
Correct |
172 ms |
3396 KB |
n=500 |
38 |
Correct |
167 ms |
3404 KB |
n=500 |
39 |
Correct |
28 ms |
3420 KB |
n=500 |
40 |
Correct |
27 ms |
3352 KB |
n=500 |
41 |
Correct |
32 ms |
3412 KB |
n=500 |
42 |
Correct |
85 ms |
3400 KB |
n=500 |
43 |
Correct |
83 ms |
3404 KB |
n=500 |
44 |
Correct |
85 ms |
3404 KB |
n=500 |
45 |
Correct |
10 ms |
3404 KB |
n=500 |
46 |
Correct |
24 ms |
3444 KB |
n=500 |
47 |
Correct |
24 ms |
3372 KB |
n=500 |
48 |
Correct |
14 ms |
3404 KB |
n=500 |
49 |
Correct |
21 ms |
3448 KB |
n=500 |
50 |
Correct |
27 ms |
3300 KB |
n=500 |
51 |
Correct |
28 ms |
3424 KB |
n=500 |
52 |
Correct |
34 ms |
3404 KB |
n=500 |
53 |
Correct |
26 ms |
3404 KB |
n=500 |
54 |
Correct |
19 ms |
3400 KB |
n=500 |
55 |
Correct |
6 ms |
1740 KB |
n=278 |
56 |
Correct |
102 ms |
3420 KB |
n=500 |
57 |
Correct |
92 ms |
3404 KB |
n=500 |
58 |
Correct |
69 ms |
3416 KB |
n=500 |
59 |
Correct |
158 ms |
16240 KB |
n=2000 |
60 |
Correct |
1051 ms |
16404 KB |
n=2000 |
61 |
Correct |
1004 ms |
16536 KB |
n=2000 |
62 |
Correct |
745 ms |
16400 KB |
n=2000 |
63 |
Correct |
171 ms |
16340 KB |
n=2000 |
64 |
Correct |
891 ms |
16328 KB |
n=2000 |
65 |
Correct |
144 ms |
16336 KB |
n=2000 |
66 |
Correct |
1199 ms |
16512 KB |
n=2000 |
67 |
Correct |
231 ms |
16268 KB |
n=2000 |
68 |
Correct |
919 ms |
16476 KB |
n=2000 |
69 |
Execution timed out |
4018 ms |
16332 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |