#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 (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 |
0 ms |
340 KB |
n=100 |
3 |
Correct |
0 ms |
340 KB |
n=100 |
4 |
Correct |
0 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 |
340 KB |
n=100 |
9 |
Correct |
0 ms |
340 KB |
n=100 |
10 |
Correct |
0 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 |
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 |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 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 |
340 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Correct |
0 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 |
0 ms |
340 KB |
n=100 |
4 |
Correct |
0 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 |
340 KB |
n=100 |
9 |
Correct |
0 ms |
340 KB |
n=100 |
10 |
Correct |
0 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 |
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 |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 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 |
340 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Correct |
0 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 |
468 KB |
n=500 |
31 |
Correct |
2 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
468 KB |
n=500 |
33 |
Correct |
3 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
6 ms |
476 KB |
n=500 |
37 |
Correct |
7 ms |
468 KB |
n=500 |
38 |
Correct |
8 ms |
468 KB |
n=500 |
39 |
Correct |
3 ms |
468 KB |
n=500 |
40 |
Correct |
3 ms |
468 KB |
n=500 |
41 |
Correct |
3 ms |
468 KB |
n=500 |
42 |
Correct |
4 ms |
468 KB |
n=500 |
43 |
Correct |
3 ms |
468 KB |
n=500 |
44 |
Correct |
3 ms |
468 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
2 ms |
468 KB |
n=500 |
47 |
Correct |
2 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
2 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
2 ms |
488 KB |
n=500 |
52 |
Correct |
3 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
11 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
97 ms |
480 KB |
n=500 |
57 |
Correct |
77 ms |
492 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
0 ms |
340 KB |
n=100 |
4 |
Correct |
0 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 |
340 KB |
n=100 |
9 |
Correct |
0 ms |
340 KB |
n=100 |
10 |
Correct |
0 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 |
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 |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 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 |
340 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Correct |
0 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 |
468 KB |
n=500 |
31 |
Correct |
2 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
468 KB |
n=500 |
33 |
Correct |
3 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
6 ms |
476 KB |
n=500 |
37 |
Correct |
7 ms |
468 KB |
n=500 |
38 |
Correct |
8 ms |
468 KB |
n=500 |
39 |
Correct |
3 ms |
468 KB |
n=500 |
40 |
Correct |
3 ms |
468 KB |
n=500 |
41 |
Correct |
3 ms |
468 KB |
n=500 |
42 |
Correct |
4 ms |
468 KB |
n=500 |
43 |
Correct |
3 ms |
468 KB |
n=500 |
44 |
Correct |
3 ms |
468 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
2 ms |
468 KB |
n=500 |
47 |
Correct |
2 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
2 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
2 ms |
488 KB |
n=500 |
52 |
Correct |
3 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
11 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
97 ms |
480 KB |
n=500 |
57 |
Correct |
77 ms |
492 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
59 |
Correct |
2 ms |
596 KB |
n=2000 |
60 |
Correct |
18 ms |
772 KB |
n=2000 |
61 |
Correct |
28 ms |
752 KB |
n=2000 |
62 |
Correct |
33 ms |
596 KB |
n=2000 |
63 |
Correct |
2 ms |
596 KB |
n=2000 |
64 |
Correct |
34 ms |
732 KB |
n=2000 |
65 |
Correct |
2 ms |
596 KB |
n=2000 |
66 |
Correct |
29 ms |
744 KB |
n=2000 |
67 |
Correct |
2 ms |
596 KB |
n=2000 |
68 |
Correct |
35 ms |
724 KB |
n=2000 |
69 |
Correct |
106 ms |
744 KB |
n=2000 |
70 |
Correct |
98 ms |
748 KB |
n=2000 |
71 |
Correct |
102 ms |
740 KB |
n=2000 |
72 |
Correct |
62 ms |
740 KB |
n=2000 |
73 |
Correct |
50 ms |
752 KB |
n=2000 |
74 |
Correct |
2 ms |
680 KB |
n=1844 |
75 |
Correct |
51 ms |
752 KB |
n=2000 |
76 |
Correct |
62 ms |
732 KB |
n=2000 |
77 |
Correct |
61 ms |
724 KB |
n=2000 |
78 |
Correct |
64 ms |
748 KB |
n=2000 |
79 |
Correct |
2 ms |
756 KB |
n=2000 |
80 |
Correct |
17 ms |
808 KB |
n=2000 |
81 |
Correct |
30 ms |
724 KB |
n=2000 |
82 |
Correct |
2 ms |
724 KB |
n=2000 |
83 |
Correct |
20 ms |
724 KB |
n=2000 |
84 |
Correct |
6 ms |
756 KB |
n=2000 |
85 |
Correct |
37 ms |
724 KB |
n=2000 |
86 |
Correct |
28 ms |
680 KB |
n=2000 |
87 |
Correct |
6 ms |
672 KB |
n=2000 |
88 |
Execution timed out |
4038 ms |
812 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
0 ms |
340 KB |
n=100 |
4 |
Correct |
0 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 |
340 KB |
n=100 |
9 |
Correct |
0 ms |
340 KB |
n=100 |
10 |
Correct |
0 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 |
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 |
340 KB |
n=100 |
18 |
Correct |
1 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
340 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 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 |
340 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Correct |
0 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 |
468 KB |
n=500 |
31 |
Correct |
2 ms |
468 KB |
n=500 |
32 |
Correct |
1 ms |
468 KB |
n=500 |
33 |
Correct |
3 ms |
468 KB |
n=500 |
34 |
Correct |
1 ms |
468 KB |
n=500 |
35 |
Correct |
1 ms |
468 KB |
n=500 |
36 |
Correct |
6 ms |
476 KB |
n=500 |
37 |
Correct |
7 ms |
468 KB |
n=500 |
38 |
Correct |
8 ms |
468 KB |
n=500 |
39 |
Correct |
3 ms |
468 KB |
n=500 |
40 |
Correct |
3 ms |
468 KB |
n=500 |
41 |
Correct |
3 ms |
468 KB |
n=500 |
42 |
Correct |
4 ms |
468 KB |
n=500 |
43 |
Correct |
3 ms |
468 KB |
n=500 |
44 |
Correct |
3 ms |
468 KB |
n=500 |
45 |
Correct |
1 ms |
468 KB |
n=500 |
46 |
Correct |
2 ms |
468 KB |
n=500 |
47 |
Correct |
2 ms |
468 KB |
n=500 |
48 |
Correct |
1 ms |
468 KB |
n=500 |
49 |
Correct |
2 ms |
468 KB |
n=500 |
50 |
Correct |
1 ms |
468 KB |
n=500 |
51 |
Correct |
2 ms |
488 KB |
n=500 |
52 |
Correct |
3 ms |
468 KB |
n=500 |
53 |
Correct |
2 ms |
468 KB |
n=500 |
54 |
Correct |
11 ms |
468 KB |
n=500 |
55 |
Correct |
1 ms |
340 KB |
n=278 |
56 |
Correct |
97 ms |
480 KB |
n=500 |
57 |
Correct |
77 ms |
492 KB |
n=500 |
58 |
Correct |
1 ms |
468 KB |
n=500 |
59 |
Correct |
2 ms |
596 KB |
n=2000 |
60 |
Correct |
18 ms |
772 KB |
n=2000 |
61 |
Correct |
28 ms |
752 KB |
n=2000 |
62 |
Correct |
33 ms |
596 KB |
n=2000 |
63 |
Correct |
2 ms |
596 KB |
n=2000 |
64 |
Correct |
34 ms |
732 KB |
n=2000 |
65 |
Correct |
2 ms |
596 KB |
n=2000 |
66 |
Correct |
29 ms |
744 KB |
n=2000 |
67 |
Correct |
2 ms |
596 KB |
n=2000 |
68 |
Correct |
35 ms |
724 KB |
n=2000 |
69 |
Correct |
106 ms |
744 KB |
n=2000 |
70 |
Correct |
98 ms |
748 KB |
n=2000 |
71 |
Correct |
102 ms |
740 KB |
n=2000 |
72 |
Correct |
62 ms |
740 KB |
n=2000 |
73 |
Correct |
50 ms |
752 KB |
n=2000 |
74 |
Correct |
2 ms |
680 KB |
n=1844 |
75 |
Correct |
51 ms |
752 KB |
n=2000 |
76 |
Correct |
62 ms |
732 KB |
n=2000 |
77 |
Correct |
61 ms |
724 KB |
n=2000 |
78 |
Correct |
64 ms |
748 KB |
n=2000 |
79 |
Correct |
2 ms |
756 KB |
n=2000 |
80 |
Correct |
17 ms |
808 KB |
n=2000 |
81 |
Correct |
30 ms |
724 KB |
n=2000 |
82 |
Correct |
2 ms |
724 KB |
n=2000 |
83 |
Correct |
20 ms |
724 KB |
n=2000 |
84 |
Correct |
6 ms |
756 KB |
n=2000 |
85 |
Correct |
37 ms |
724 KB |
n=2000 |
86 |
Correct |
28 ms |
680 KB |
n=2000 |
87 |
Correct |
6 ms |
672 KB |
n=2000 |
88 |
Execution timed out |
4038 ms |
812 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |