#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 105;
const int LOG = 20;
int a[N], n, m, q;
vector<int> g[N];
int depth[N], parent[N][LOG];
void dfs(int v, int p) {
parent[v][0] = p;
for (int i = 1; i < LOG; i++) {
if (parent[v][i-1] != 0)
parent[v][i] = parent[parent[v][i-1]][i-1];
else
parent[v][i] = 0;
}
for (int to : g[v]) {
if (to != p) {
depth[to] = depth[v] + 1;
dfs(to, v);
}
}
}
int lca(int u, int v) {
if (depth[u] < depth[v]) swap(u, v);
for (int i = LOG - 1; i >= 0; i--) {
if (depth[u] - (1 << i) >= depth[v]) {
u = parent[u][i];
}
}
if (u == v) return u;
for (int i = LOG - 1; i >= 0; i--) {
if (parent[u][i] != parent[v][i]) {
u = parent[u][i];
v = parent[v][i];
}
}
return parent[u][0];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= m; i++) {
cin >> a[i];
}
depth[1] = 0;
dfs(1, 0);
while (q--) {
int type;
cin >> type;
if (type == 1) {
int pos, v;
cin >> pos >> v;
a[pos] = v;
} else {
int l, r, v;
cin >> l >> r >> v;
bool found = false;
for (int x = l; x <= r; x++) {
for (int y = x; y <= r; y++) {
if (lca(a[x], a[y]) == v) {
cout << x << " " << y << "\n";
found = true;
break;
}
}
if (found) break;
}
if (!found) {
cout << "-1 -1\n";
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Incorrect |
3 ms |
336 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Incorrect |
3 ms |
336 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Incorrect |
3 ms |
336 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
n=5 |
2 |
Incorrect |
3 ms |
336 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |