#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)2e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, m, q, a[N], val[501][501];
int timer, tin[N], tout[N], up[N][19];
vector<int> g[N];
void calc(int v, int pr) {
up[v][0] = pr;
tin[v] = ++timer;
for(int i = 1; i <= 18; ++i) {
up[v][i] = up[up[v][i-1]][i-1];
}
for(auto to : g[v]) {
if(to != pr) {
calc(to, v);
}
}
tout[v] = ++timer;
}
bool is_parent(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int u, int v) {
if(is_parent(u, v)) return u;
if(is_parent(v, u)) return v;
for(int i = 18; i >= 0; --i) {
if(!is_parent(up[u][i], v)) {
u = up[u][i];
}
}
return up[u][0];
}
void solve() {
cin >> n >> m >> q;
for(int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for(int i = 1; i <= m; ++i) cin >> a[i];
calc(1, 1);
for(int i = 1; i <= m; ++i) {
int x = a[i];
for(int j = i; j <= m; ++j) {
x = lca(x, a[j]);
val[i][j] = x;
}
}
while(q--) {
char tp;
cin >> tp;
int l, r, v;
if(tp == '1') {
cin >> l >> r;
a[l] = r;
for(int i = 1; i <= m; ++i) {
int x = a[i];
for(int j = i; j <= m; ++j) {
x = lca(x, a[j]);
val[i][j] = x;
}
}
} else {
cin >> l >> r >> v;
int a = -1, b = -1;
for(int i = l; i <= r && a == -1; ++i) {
for(int j = i; j <= r; ++j) {
if(val[i][j] == v) {
a = i;
b = j;
break;
}
}
}
cout << a << ' ' << b << nl;
}
}
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}
/*
3
3 1
2 3
1 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
5452 KB |
n=100 |
3 |
Correct |
4 ms |
5452 KB |
n=100 |
4 |
Correct |
5 ms |
5452 KB |
n=100 |
5 |
Correct |
4 ms |
5456 KB |
n=100 |
6 |
Correct |
3 ms |
5452 KB |
n=100 |
7 |
Correct |
3 ms |
5452 KB |
n=100 |
8 |
Correct |
3 ms |
5452 KB |
n=100 |
9 |
Correct |
2 ms |
5452 KB |
n=100 |
10 |
Correct |
4 ms |
5452 KB |
n=100 |
11 |
Correct |
4 ms |
5452 KB |
n=100 |
12 |
Correct |
4 ms |
5452 KB |
n=100 |
13 |
Correct |
5 ms |
5452 KB |
n=100 |
14 |
Correct |
4 ms |
5460 KB |
n=100 |
15 |
Correct |
4 ms |
5452 KB |
n=100 |
16 |
Correct |
4 ms |
5460 KB |
n=100 |
17 |
Correct |
3 ms |
5452 KB |
n=100 |
18 |
Correct |
3 ms |
5452 KB |
n=100 |
19 |
Correct |
4 ms |
5452 KB |
n=100 |
20 |
Correct |
4 ms |
5452 KB |
n=100 |
21 |
Correct |
3 ms |
5452 KB |
n=100 |
22 |
Correct |
4 ms |
5460 KB |
n=100 |
23 |
Correct |
4 ms |
5452 KB |
n=100 |
24 |
Correct |
4 ms |
5452 KB |
n=100 |
25 |
Correct |
4 ms |
5452 KB |
n=100 |
26 |
Correct |
2 ms |
5196 KB |
n=12 |
27 |
Correct |
3 ms |
5452 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
5452 KB |
n=100 |
3 |
Correct |
4 ms |
5452 KB |
n=100 |
4 |
Correct |
5 ms |
5452 KB |
n=100 |
5 |
Correct |
4 ms |
5456 KB |
n=100 |
6 |
Correct |
3 ms |
5452 KB |
n=100 |
7 |
Correct |
3 ms |
5452 KB |
n=100 |
8 |
Correct |
3 ms |
5452 KB |
n=100 |
9 |
Correct |
2 ms |
5452 KB |
n=100 |
10 |
Correct |
4 ms |
5452 KB |
n=100 |
11 |
Correct |
4 ms |
5452 KB |
n=100 |
12 |
Correct |
4 ms |
5452 KB |
n=100 |
13 |
Correct |
5 ms |
5452 KB |
n=100 |
14 |
Correct |
4 ms |
5460 KB |
n=100 |
15 |
Correct |
4 ms |
5452 KB |
n=100 |
16 |
Correct |
4 ms |
5460 KB |
n=100 |
17 |
Correct |
3 ms |
5452 KB |
n=100 |
18 |
Correct |
3 ms |
5452 KB |
n=100 |
19 |
Correct |
4 ms |
5452 KB |
n=100 |
20 |
Correct |
4 ms |
5452 KB |
n=100 |
21 |
Correct |
3 ms |
5452 KB |
n=100 |
22 |
Correct |
4 ms |
5460 KB |
n=100 |
23 |
Correct |
4 ms |
5452 KB |
n=100 |
24 |
Correct |
4 ms |
5452 KB |
n=100 |
25 |
Correct |
4 ms |
5452 KB |
n=100 |
26 |
Correct |
2 ms |
5196 KB |
n=12 |
27 |
Correct |
3 ms |
5452 KB |
n=100 |
28 |
Correct |
113 ms |
7076 KB |
n=500 |
29 |
Correct |
91 ms |
7080 KB |
n=500 |
30 |
Correct |
104 ms |
7116 KB |
n=500 |
31 |
Correct |
132 ms |
7108 KB |
n=500 |
32 |
Correct |
107 ms |
7116 KB |
n=500 |
33 |
Correct |
109 ms |
7116 KB |
n=500 |
34 |
Correct |
111 ms |
7116 KB |
n=500 |
35 |
Correct |
107 ms |
7116 KB |
n=500 |
36 |
Correct |
23 ms |
7076 KB |
n=500 |
37 |
Correct |
26 ms |
7116 KB |
n=500 |
38 |
Correct |
26 ms |
7116 KB |
n=500 |
39 |
Correct |
7 ms |
7116 KB |
n=500 |
40 |
Correct |
7 ms |
7076 KB |
n=500 |
41 |
Correct |
7 ms |
7116 KB |
n=500 |
42 |
Correct |
121 ms |
7116 KB |
n=500 |
43 |
Correct |
125 ms |
7116 KB |
n=500 |
44 |
Correct |
139 ms |
7116 KB |
n=500 |
45 |
Correct |
102 ms |
7116 KB |
n=500 |
46 |
Correct |
98 ms |
7116 KB |
n=500 |
47 |
Correct |
103 ms |
7116 KB |
n=500 |
48 |
Correct |
109 ms |
6988 KB |
n=500 |
49 |
Correct |
100 ms |
7132 KB |
n=500 |
50 |
Correct |
107 ms |
7116 KB |
n=500 |
51 |
Correct |
117 ms |
7116 KB |
n=500 |
52 |
Correct |
94 ms |
7236 KB |
n=500 |
53 |
Correct |
113 ms |
7116 KB |
n=500 |
54 |
Correct |
110 ms |
7204 KB |
n=500 |
55 |
Correct |
30 ms |
6920 KB |
n=278 |
56 |
Correct |
110 ms |
7116 KB |
n=500 |
57 |
Correct |
107 ms |
7116 KB |
n=500 |
58 |
Correct |
21 ms |
7084 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
5452 KB |
n=100 |
3 |
Correct |
4 ms |
5452 KB |
n=100 |
4 |
Correct |
5 ms |
5452 KB |
n=100 |
5 |
Correct |
4 ms |
5456 KB |
n=100 |
6 |
Correct |
3 ms |
5452 KB |
n=100 |
7 |
Correct |
3 ms |
5452 KB |
n=100 |
8 |
Correct |
3 ms |
5452 KB |
n=100 |
9 |
Correct |
2 ms |
5452 KB |
n=100 |
10 |
Correct |
4 ms |
5452 KB |
n=100 |
11 |
Correct |
4 ms |
5452 KB |
n=100 |
12 |
Correct |
4 ms |
5452 KB |
n=100 |
13 |
Correct |
5 ms |
5452 KB |
n=100 |
14 |
Correct |
4 ms |
5460 KB |
n=100 |
15 |
Correct |
4 ms |
5452 KB |
n=100 |
16 |
Correct |
4 ms |
5460 KB |
n=100 |
17 |
Correct |
3 ms |
5452 KB |
n=100 |
18 |
Correct |
3 ms |
5452 KB |
n=100 |
19 |
Correct |
4 ms |
5452 KB |
n=100 |
20 |
Correct |
4 ms |
5452 KB |
n=100 |
21 |
Correct |
3 ms |
5452 KB |
n=100 |
22 |
Correct |
4 ms |
5460 KB |
n=100 |
23 |
Correct |
4 ms |
5452 KB |
n=100 |
24 |
Correct |
4 ms |
5452 KB |
n=100 |
25 |
Correct |
4 ms |
5452 KB |
n=100 |
26 |
Correct |
2 ms |
5196 KB |
n=12 |
27 |
Correct |
3 ms |
5452 KB |
n=100 |
28 |
Correct |
113 ms |
7076 KB |
n=500 |
29 |
Correct |
91 ms |
7080 KB |
n=500 |
30 |
Correct |
104 ms |
7116 KB |
n=500 |
31 |
Correct |
132 ms |
7108 KB |
n=500 |
32 |
Correct |
107 ms |
7116 KB |
n=500 |
33 |
Correct |
109 ms |
7116 KB |
n=500 |
34 |
Correct |
111 ms |
7116 KB |
n=500 |
35 |
Correct |
107 ms |
7116 KB |
n=500 |
36 |
Correct |
23 ms |
7076 KB |
n=500 |
37 |
Correct |
26 ms |
7116 KB |
n=500 |
38 |
Correct |
26 ms |
7116 KB |
n=500 |
39 |
Correct |
7 ms |
7116 KB |
n=500 |
40 |
Correct |
7 ms |
7076 KB |
n=500 |
41 |
Correct |
7 ms |
7116 KB |
n=500 |
42 |
Correct |
121 ms |
7116 KB |
n=500 |
43 |
Correct |
125 ms |
7116 KB |
n=500 |
44 |
Correct |
139 ms |
7116 KB |
n=500 |
45 |
Correct |
102 ms |
7116 KB |
n=500 |
46 |
Correct |
98 ms |
7116 KB |
n=500 |
47 |
Correct |
103 ms |
7116 KB |
n=500 |
48 |
Correct |
109 ms |
6988 KB |
n=500 |
49 |
Correct |
100 ms |
7132 KB |
n=500 |
50 |
Correct |
107 ms |
7116 KB |
n=500 |
51 |
Correct |
117 ms |
7116 KB |
n=500 |
52 |
Correct |
94 ms |
7236 KB |
n=500 |
53 |
Correct |
113 ms |
7116 KB |
n=500 |
54 |
Correct |
110 ms |
7204 KB |
n=500 |
55 |
Correct |
30 ms |
6920 KB |
n=278 |
56 |
Correct |
110 ms |
7116 KB |
n=500 |
57 |
Correct |
107 ms |
7116 KB |
n=500 |
58 |
Correct |
21 ms |
7084 KB |
n=500 |
59 |
Runtime error |
17 ms |
17932 KB |
Execution killed with signal 11 |
60 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
n=5 |
2 |
Correct |
4 ms |
5452 KB |
n=100 |
3 |
Correct |
4 ms |
5452 KB |
n=100 |
4 |
Correct |
5 ms |
5452 KB |
n=100 |
5 |
Correct |
4 ms |
5456 KB |
n=100 |
6 |
Correct |
3 ms |
5452 KB |
n=100 |
7 |
Correct |
3 ms |
5452 KB |
n=100 |
8 |
Correct |
3 ms |
5452 KB |
n=100 |
9 |
Correct |
2 ms |
5452 KB |
n=100 |
10 |
Correct |
4 ms |
5452 KB |
n=100 |
11 |
Correct |
4 ms |
5452 KB |
n=100 |
12 |
Correct |
4 ms |
5452 KB |
n=100 |
13 |
Correct |
5 ms |
5452 KB |
n=100 |
14 |
Correct |
4 ms |
5460 KB |
n=100 |
15 |
Correct |
4 ms |
5452 KB |
n=100 |
16 |
Correct |
4 ms |
5460 KB |
n=100 |
17 |
Correct |
3 ms |
5452 KB |
n=100 |
18 |
Correct |
3 ms |
5452 KB |
n=100 |
19 |
Correct |
4 ms |
5452 KB |
n=100 |
20 |
Correct |
4 ms |
5452 KB |
n=100 |
21 |
Correct |
3 ms |
5452 KB |
n=100 |
22 |
Correct |
4 ms |
5460 KB |
n=100 |
23 |
Correct |
4 ms |
5452 KB |
n=100 |
24 |
Correct |
4 ms |
5452 KB |
n=100 |
25 |
Correct |
4 ms |
5452 KB |
n=100 |
26 |
Correct |
2 ms |
5196 KB |
n=12 |
27 |
Correct |
3 ms |
5452 KB |
n=100 |
28 |
Correct |
113 ms |
7076 KB |
n=500 |
29 |
Correct |
91 ms |
7080 KB |
n=500 |
30 |
Correct |
104 ms |
7116 KB |
n=500 |
31 |
Correct |
132 ms |
7108 KB |
n=500 |
32 |
Correct |
107 ms |
7116 KB |
n=500 |
33 |
Correct |
109 ms |
7116 KB |
n=500 |
34 |
Correct |
111 ms |
7116 KB |
n=500 |
35 |
Correct |
107 ms |
7116 KB |
n=500 |
36 |
Correct |
23 ms |
7076 KB |
n=500 |
37 |
Correct |
26 ms |
7116 KB |
n=500 |
38 |
Correct |
26 ms |
7116 KB |
n=500 |
39 |
Correct |
7 ms |
7116 KB |
n=500 |
40 |
Correct |
7 ms |
7076 KB |
n=500 |
41 |
Correct |
7 ms |
7116 KB |
n=500 |
42 |
Correct |
121 ms |
7116 KB |
n=500 |
43 |
Correct |
125 ms |
7116 KB |
n=500 |
44 |
Correct |
139 ms |
7116 KB |
n=500 |
45 |
Correct |
102 ms |
7116 KB |
n=500 |
46 |
Correct |
98 ms |
7116 KB |
n=500 |
47 |
Correct |
103 ms |
7116 KB |
n=500 |
48 |
Correct |
109 ms |
6988 KB |
n=500 |
49 |
Correct |
100 ms |
7132 KB |
n=500 |
50 |
Correct |
107 ms |
7116 KB |
n=500 |
51 |
Correct |
117 ms |
7116 KB |
n=500 |
52 |
Correct |
94 ms |
7236 KB |
n=500 |
53 |
Correct |
113 ms |
7116 KB |
n=500 |
54 |
Correct |
110 ms |
7204 KB |
n=500 |
55 |
Correct |
30 ms |
6920 KB |
n=278 |
56 |
Correct |
110 ms |
7116 KB |
n=500 |
57 |
Correct |
107 ms |
7116 KB |
n=500 |
58 |
Correct |
21 ms |
7084 KB |
n=500 |
59 |
Runtime error |
17 ms |
17932 KB |
Execution killed with signal 11 |
60 |
Halted |
0 ms |
0 KB |
- |