#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 (!is_par(v , c)) break;
if (j == r) x = 1;
}
if (x != -1) break;
}
if (y == -1) cout<<-1<<" "<<-1<<'\n';
else 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 |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
412 KB |
n=100 |
11 |
Correct |
1 ms |
412 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
404 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
404 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
400 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
408 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
404 KB |
n=100 |
25 |
Correct |
0 ms |
408 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 |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
412 KB |
n=100 |
11 |
Correct |
1 ms |
412 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
404 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
404 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
400 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
408 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
404 KB |
n=100 |
25 |
Correct |
0 ms |
408 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 |
1 ms |
468 KB |
n=500 |
30 |
Correct |
2 ms |
420 KB |
n=500 |
31 |
Correct |
2 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
408 KB |
n=500 |
33 |
Correct |
3 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
2 ms |
468 KB |
n=500 |
36 |
Correct |
7 ms |
468 KB |
n=500 |
37 |
Correct |
6 ms |
508 KB |
n=500 |
38 |
Correct |
5 ms |
468 KB |
n=500 |
39 |
Correct |
5 ms |
468 KB |
n=500 |
40 |
Correct |
4 ms |
416 KB |
n=500 |
41 |
Correct |
4 ms |
468 KB |
n=500 |
42 |
Correct |
4 ms |
468 KB |
n=500 |
43 |
Correct |
4 ms |
468 KB |
n=500 |
44 |
Correct |
3 ms |
468 KB |
n=500 |
45 |
Correct |
1 ms |
412 KB |
n=500 |
46 |
Correct |
2 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
2 ms |
412 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
3 ms |
468 KB |
n=500 |
52 |
Correct |
2 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
420 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
412 KB |
n=100 |
11 |
Correct |
1 ms |
412 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
404 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
404 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
400 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
408 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
404 KB |
n=100 |
25 |
Correct |
0 ms |
408 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 |
1 ms |
468 KB |
n=500 |
30 |
Correct |
2 ms |
420 KB |
n=500 |
31 |
Correct |
2 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
408 KB |
n=500 |
33 |
Correct |
3 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
2 ms |
468 KB |
n=500 |
36 |
Correct |
7 ms |
468 KB |
n=500 |
37 |
Correct |
6 ms |
508 KB |
n=500 |
38 |
Correct |
5 ms |
468 KB |
n=500 |
39 |
Correct |
5 ms |
468 KB |
n=500 |
40 |
Correct |
4 ms |
416 KB |
n=500 |
41 |
Correct |
4 ms |
468 KB |
n=500 |
42 |
Correct |
4 ms |
468 KB |
n=500 |
43 |
Correct |
4 ms |
468 KB |
n=500 |
44 |
Correct |
3 ms |
468 KB |
n=500 |
45 |
Correct |
1 ms |
412 KB |
n=500 |
46 |
Correct |
2 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
2 ms |
412 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
3 ms |
468 KB |
n=500 |
52 |
Correct |
2 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
420 KB |
n=500 |
59 |
Correct |
2 ms |
724 KB |
n=2000 |
60 |
Correct |
20 ms |
724 KB |
n=2000 |
61 |
Correct |
28 ms |
936 KB |
n=2000 |
62 |
Correct |
38 ms |
724 KB |
n=2000 |
63 |
Correct |
2 ms |
764 KB |
n=2000 |
64 |
Correct |
34 ms |
724 KB |
n=2000 |
65 |
Correct |
2 ms |
676 KB |
n=2000 |
66 |
Correct |
27 ms |
724 KB |
n=2000 |
67 |
Correct |
2 ms |
724 KB |
n=2000 |
68 |
Correct |
32 ms |
724 KB |
n=2000 |
69 |
Correct |
97 ms |
748 KB |
n=2000 |
70 |
Correct |
94 ms |
752 KB |
n=2000 |
71 |
Correct |
92 ms |
732 KB |
n=2000 |
72 |
Correct |
54 ms |
740 KB |
n=2000 |
73 |
Correct |
50 ms |
756 KB |
n=2000 |
74 |
Correct |
2 ms |
724 KB |
n=1844 |
75 |
Correct |
49 ms |
760 KB |
n=2000 |
76 |
Correct |
62 ms |
744 KB |
n=2000 |
77 |
Correct |
61 ms |
732 KB |
n=2000 |
78 |
Correct |
63 ms |
748 KB |
n=2000 |
79 |
Correct |
2 ms |
724 KB |
n=2000 |
80 |
Correct |
17 ms |
816 KB |
n=2000 |
81 |
Correct |
29 ms |
772 KB |
n=2000 |
82 |
Correct |
2 ms |
724 KB |
n=2000 |
83 |
Correct |
21 ms |
724 KB |
n=2000 |
84 |
Correct |
6 ms |
760 KB |
n=2000 |
85 |
Correct |
30 ms |
724 KB |
n=2000 |
86 |
Correct |
23 ms |
888 KB |
n=2000 |
87 |
Correct |
6 ms |
724 KB |
n=2000 |
88 |
Correct |
9 ms |
756 KB |
n=2000 |
89 |
Correct |
8 ms |
836 KB |
n=2000 |
90 |
Correct |
6 ms |
724 KB |
n=2000 |
91 |
Correct |
15 ms |
724 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
340 KB |
n=100 |
4 |
Correct |
1 ms |
340 KB |
n=100 |
5 |
Correct |
1 ms |
340 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
340 KB |
n=100 |
8 |
Correct |
1 ms |
408 KB |
n=100 |
9 |
Correct |
1 ms |
340 KB |
n=100 |
10 |
Correct |
1 ms |
412 KB |
n=100 |
11 |
Correct |
1 ms |
412 KB |
n=100 |
12 |
Correct |
1 ms |
340 KB |
n=100 |
13 |
Correct |
1 ms |
404 KB |
n=100 |
14 |
Correct |
1 ms |
340 KB |
n=100 |
15 |
Correct |
1 ms |
340 KB |
n=100 |
16 |
Correct |
1 ms |
340 KB |
n=100 |
17 |
Correct |
1 ms |
404 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
1 ms |
400 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
408 KB |
n=100 |
22 |
Correct |
1 ms |
340 KB |
n=100 |
23 |
Correct |
1 ms |
340 KB |
n=100 |
24 |
Correct |
1 ms |
404 KB |
n=100 |
25 |
Correct |
0 ms |
408 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 |
1 ms |
468 KB |
n=500 |
30 |
Correct |
2 ms |
420 KB |
n=500 |
31 |
Correct |
2 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
408 KB |
n=500 |
33 |
Correct |
3 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
2 ms |
468 KB |
n=500 |
36 |
Correct |
7 ms |
468 KB |
n=500 |
37 |
Correct |
6 ms |
508 KB |
n=500 |
38 |
Correct |
5 ms |
468 KB |
n=500 |
39 |
Correct |
5 ms |
468 KB |
n=500 |
40 |
Correct |
4 ms |
416 KB |
n=500 |
41 |
Correct |
4 ms |
468 KB |
n=500 |
42 |
Correct |
4 ms |
468 KB |
n=500 |
43 |
Correct |
4 ms |
468 KB |
n=500 |
44 |
Correct |
3 ms |
468 KB |
n=500 |
45 |
Correct |
1 ms |
412 KB |
n=500 |
46 |
Correct |
2 ms |
468 KB |
n=500 |
47 |
Correct |
1 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
2 ms |
412 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
3 ms |
468 KB |
n=500 |
52 |
Correct |
2 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
1 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
1 ms |
468 KB |
n=500 |
57 |
Correct |
1 ms |
468 KB |
n=500 |
58 |
Correct |
1 ms |
420 KB |
n=500 |
59 |
Correct |
2 ms |
724 KB |
n=2000 |
60 |
Correct |
20 ms |
724 KB |
n=2000 |
61 |
Correct |
28 ms |
936 KB |
n=2000 |
62 |
Correct |
38 ms |
724 KB |
n=2000 |
63 |
Correct |
2 ms |
764 KB |
n=2000 |
64 |
Correct |
34 ms |
724 KB |
n=2000 |
65 |
Correct |
2 ms |
676 KB |
n=2000 |
66 |
Correct |
27 ms |
724 KB |
n=2000 |
67 |
Correct |
2 ms |
724 KB |
n=2000 |
68 |
Correct |
32 ms |
724 KB |
n=2000 |
69 |
Correct |
97 ms |
748 KB |
n=2000 |
70 |
Correct |
94 ms |
752 KB |
n=2000 |
71 |
Correct |
92 ms |
732 KB |
n=2000 |
72 |
Correct |
54 ms |
740 KB |
n=2000 |
73 |
Correct |
50 ms |
756 KB |
n=2000 |
74 |
Correct |
2 ms |
724 KB |
n=1844 |
75 |
Correct |
49 ms |
760 KB |
n=2000 |
76 |
Correct |
62 ms |
744 KB |
n=2000 |
77 |
Correct |
61 ms |
732 KB |
n=2000 |
78 |
Correct |
63 ms |
748 KB |
n=2000 |
79 |
Correct |
2 ms |
724 KB |
n=2000 |
80 |
Correct |
17 ms |
816 KB |
n=2000 |
81 |
Correct |
29 ms |
772 KB |
n=2000 |
82 |
Correct |
2 ms |
724 KB |
n=2000 |
83 |
Correct |
21 ms |
724 KB |
n=2000 |
84 |
Correct |
6 ms |
760 KB |
n=2000 |
85 |
Correct |
30 ms |
724 KB |
n=2000 |
86 |
Correct |
23 ms |
888 KB |
n=2000 |
87 |
Correct |
6 ms |
724 KB |
n=2000 |
88 |
Correct |
9 ms |
756 KB |
n=2000 |
89 |
Correct |
8 ms |
836 KB |
n=2000 |
90 |
Correct |
6 ms |
724 KB |
n=2000 |
91 |
Correct |
15 ms |
724 KB |
n=2000 |
92 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |