#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define sc second
#define pb push_back
#define in insert
vector <ll> g[2001], tin(2001) , tout(2001);
ll up[2001][13] , cur;
void dfs (ll v, ll p) {
tin[v] = ++cur;
for (int i = 1; i <= 12; i++)
up[v][i] = up[up[v][i - 1]][i - 1];
for (auto k : g[v]) {
if (k == p) continue;
up[k][0] = v;
dfs(k , v);
}
tout[v] = ++cur;
}
bool is_par(ll a, ll b) {
if (tin[a] <= tin[b] && tout[a] >= tout[b]) return 1;
else return 0;
}
ll lca (ll a, ll b) {
if (is_par(a , b)) return a;
if (is_par(b , a)) return b;
for (int i = 12; i >= 0; i--) {
if (!is_par(up[a][i] , b)) a = up[a][i];
}
return up[a][0];
}
void dambo_12() {
ll n , m , q; cin>>n>>m>>q;
for (int i = 1; i < n; i++){
ll a , b; cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
up[1][0] = 1;
dfs(1 , 1);
vector <ll> a(m + 1 , 0);
for (int i = 1; i <= m; i++)
cin>>a[i];
for (int it = 1; it <= q; it++) {
int tp; cin>>tp;
if (tp == 1) {
int pos ; ll v; cin>>pos>>v;
a[pos] = v;
}
else {
int l , r , v; cin>>l>>r>>v;
int x = -1 , y = -1;
for (int i = l; i <= r; i++){
int c = a[i];
for (int j = i; j <= r; j++){
c = lca(c , a[j]);
if (c == v) {
x = i; y = j; break;
}
}
if (x != -1) break;
}
cout<<x<<" "<<y<<'\n';
}
}
return;
}
int32_t main () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll o = 1; //cin>>o;
while (o--) {
dambo_12();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
408 KB |
n=100 |
5 |
Correct |
1 ms |
408 KB |
n=100 |
6 |
Correct |
2 ms |
400 KB |
n=100 |
7 |
Correct |
2 ms |
412 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
2 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
408 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
408 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
412 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
408 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
340 KB |
n=12 |
27 |
Correct |
1 ms |
340 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
408 KB |
n=100 |
5 |
Correct |
1 ms |
408 KB |
n=100 |
6 |
Correct |
2 ms |
400 KB |
n=100 |
7 |
Correct |
2 ms |
412 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
2 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
408 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
408 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
412 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
408 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
340 KB |
n=12 |
27 |
Correct |
1 ms |
340 KB |
n=100 |
28 |
Correct |
1 ms |
468 KB |
n=500 |
29 |
Correct |
12 ms |
468 KB |
n=500 |
30 |
Correct |
10 ms |
552 KB |
n=500 |
31 |
Correct |
11 ms |
508 KB |
n=500 |
32 |
Correct |
2 ms |
468 KB |
n=500 |
33 |
Correct |
10 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
10 ms |
468 KB |
n=500 |
36 |
Correct |
119 ms |
468 KB |
n=500 |
37 |
Correct |
124 ms |
468 KB |
n=500 |
38 |
Correct |
138 ms |
612 KB |
n=500 |
39 |
Correct |
21 ms |
496 KB |
n=500 |
40 |
Correct |
21 ms |
468 KB |
n=500 |
41 |
Correct |
18 ms |
500 KB |
n=500 |
42 |
Correct |
68 ms |
468 KB |
n=500 |
43 |
Correct |
65 ms |
472 KB |
n=500 |
44 |
Correct |
61 ms |
480 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
11 ms |
512 KB |
n=500 |
47 |
Correct |
10 ms |
508 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
9 ms |
512 KB |
n=500 |
50 |
Correct |
16 ms |
492 KB |
n=500 |
51 |
Correct |
17 ms |
500 KB |
n=500 |
52 |
Correct |
20 ms |
468 KB |
n=500 |
53 |
Correct |
19 ms |
468 KB |
n=500 |
54 |
Correct |
8 ms |
468 KB |
n=500 |
55 |
Correct |
3 ms |
340 KB |
n=278 |
56 |
Correct |
64 ms |
412 KB |
n=500 |
57 |
Correct |
66 ms |
468 KB |
n=500 |
58 |
Correct |
56 ms |
424 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
408 KB |
n=100 |
5 |
Correct |
1 ms |
408 KB |
n=100 |
6 |
Correct |
2 ms |
400 KB |
n=100 |
7 |
Correct |
2 ms |
412 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
2 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
408 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
408 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
412 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
408 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
340 KB |
n=12 |
27 |
Correct |
1 ms |
340 KB |
n=100 |
28 |
Correct |
1 ms |
468 KB |
n=500 |
29 |
Correct |
12 ms |
468 KB |
n=500 |
30 |
Correct |
10 ms |
552 KB |
n=500 |
31 |
Correct |
11 ms |
508 KB |
n=500 |
32 |
Correct |
2 ms |
468 KB |
n=500 |
33 |
Correct |
10 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
10 ms |
468 KB |
n=500 |
36 |
Correct |
119 ms |
468 KB |
n=500 |
37 |
Correct |
124 ms |
468 KB |
n=500 |
38 |
Correct |
138 ms |
612 KB |
n=500 |
39 |
Correct |
21 ms |
496 KB |
n=500 |
40 |
Correct |
21 ms |
468 KB |
n=500 |
41 |
Correct |
18 ms |
500 KB |
n=500 |
42 |
Correct |
68 ms |
468 KB |
n=500 |
43 |
Correct |
65 ms |
472 KB |
n=500 |
44 |
Correct |
61 ms |
480 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
11 ms |
512 KB |
n=500 |
47 |
Correct |
10 ms |
508 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
9 ms |
512 KB |
n=500 |
50 |
Correct |
16 ms |
492 KB |
n=500 |
51 |
Correct |
17 ms |
500 KB |
n=500 |
52 |
Correct |
20 ms |
468 KB |
n=500 |
53 |
Correct |
19 ms |
468 KB |
n=500 |
54 |
Correct |
8 ms |
468 KB |
n=500 |
55 |
Correct |
3 ms |
340 KB |
n=278 |
56 |
Correct |
64 ms |
412 KB |
n=500 |
57 |
Correct |
66 ms |
468 KB |
n=500 |
58 |
Correct |
56 ms |
424 KB |
n=500 |
59 |
Correct |
10 ms |
764 KB |
n=2000 |
60 |
Correct |
613 ms |
816 KB |
n=2000 |
61 |
Correct |
589 ms |
784 KB |
n=2000 |
62 |
Correct |
412 ms |
848 KB |
n=2000 |
63 |
Correct |
15 ms |
724 KB |
n=2000 |
64 |
Correct |
526 ms |
760 KB |
n=2000 |
65 |
Correct |
3 ms |
724 KB |
n=2000 |
66 |
Correct |
665 ms |
800 KB |
n=2000 |
67 |
Correct |
32 ms |
848 KB |
n=2000 |
68 |
Correct |
535 ms |
776 KB |
n=2000 |
69 |
Execution timed out |
4054 ms |
844 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
1 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
408 KB |
n=100 |
5 |
Correct |
1 ms |
408 KB |
n=100 |
6 |
Correct |
2 ms |
400 KB |
n=100 |
7 |
Correct |
2 ms |
412 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
2 ms |
340 KB |
n=100 |
11 |
Correct |
1 ms |
340 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
340 KB |
n=100 |
14 |
Correct |
0 ms |
408 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
408 KB |
n=100 |
17 |
Correct |
1 ms |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
412 KB |
n=100 |
21 |
Correct |
1 ms |
340 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
408 KB |
n=100 |
25 |
Correct |
1 ms |
340 KB |
n=100 |
26 |
Correct |
1 ms |
340 KB |
n=12 |
27 |
Correct |
1 ms |
340 KB |
n=100 |
28 |
Correct |
1 ms |
468 KB |
n=500 |
29 |
Correct |
12 ms |
468 KB |
n=500 |
30 |
Correct |
10 ms |
552 KB |
n=500 |
31 |
Correct |
11 ms |
508 KB |
n=500 |
32 |
Correct |
2 ms |
468 KB |
n=500 |
33 |
Correct |
10 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
10 ms |
468 KB |
n=500 |
36 |
Correct |
119 ms |
468 KB |
n=500 |
37 |
Correct |
124 ms |
468 KB |
n=500 |
38 |
Correct |
138 ms |
612 KB |
n=500 |
39 |
Correct |
21 ms |
496 KB |
n=500 |
40 |
Correct |
21 ms |
468 KB |
n=500 |
41 |
Correct |
18 ms |
500 KB |
n=500 |
42 |
Correct |
68 ms |
468 KB |
n=500 |
43 |
Correct |
65 ms |
472 KB |
n=500 |
44 |
Correct |
61 ms |
480 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
11 ms |
512 KB |
n=500 |
47 |
Correct |
10 ms |
508 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
9 ms |
512 KB |
n=500 |
50 |
Correct |
16 ms |
492 KB |
n=500 |
51 |
Correct |
17 ms |
500 KB |
n=500 |
52 |
Correct |
20 ms |
468 KB |
n=500 |
53 |
Correct |
19 ms |
468 KB |
n=500 |
54 |
Correct |
8 ms |
468 KB |
n=500 |
55 |
Correct |
3 ms |
340 KB |
n=278 |
56 |
Correct |
64 ms |
412 KB |
n=500 |
57 |
Correct |
66 ms |
468 KB |
n=500 |
58 |
Correct |
56 ms |
424 KB |
n=500 |
59 |
Correct |
10 ms |
764 KB |
n=2000 |
60 |
Correct |
613 ms |
816 KB |
n=2000 |
61 |
Correct |
589 ms |
784 KB |
n=2000 |
62 |
Correct |
412 ms |
848 KB |
n=2000 |
63 |
Correct |
15 ms |
724 KB |
n=2000 |
64 |
Correct |
526 ms |
760 KB |
n=2000 |
65 |
Correct |
3 ms |
724 KB |
n=2000 |
66 |
Correct |
665 ms |
800 KB |
n=2000 |
67 |
Correct |
32 ms |
848 KB |
n=2000 |
68 |
Correct |
535 ms |
776 KB |
n=2000 |
69 |
Execution timed out |
4054 ms |
844 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |