// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee //
// 271828___182845__904523__53602__ //
// 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 //
// 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ //
// 35___35____47______59____45713__ //
// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee //
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;
vector<int> a, tin, tout;
vector<vector<int>> gp, up;
int n, m, q, timer = 0;
void dfs(int v, int p)
{
tin[v] = ++timer;
up[v][0] = p;
for (int i = 1; i < 20; ++i)
up[v][i] = up[up[v][i - 1]][i - 1];
for (int u : gp[v]) {
if (u != p)
dfs(u, v);
}
tout[v] = ++timer;
}
bool is_ancestor(int u, int v)
{
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int u, int v)
{
if (is_ancestor(u, v))
return u;
if (is_ancestor(v, u))
return v;
for (int i = 19; i >= 0; --i) {
if (!is_ancestor(up[u][i], v))
u = up[u][i];
}
return up[u][0];
}
void solve() {
cin >> n >> m >> q;
a = tin = tout = vector<int>(n);
gp = vector<vector<int>>(n);
up = vector<vector<int>>(n, vector<int>(20));
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
gp[--u].push_back(--v);
gp[v].push_back(u);
}
for (int i = 0; i < m; ++i) cin >> a[i],--a[i];
dfs(0, 0);
while (q--) {
int type; cin >> type;
if (type == 2) {
int l, r, v; cin >> l >> r >> v;
--l, --r, --v;
bool f = 0;
while (l < n && l <= r) {
if (a[l] == v) {
cout << l + 1 << " " << l + 1 << '\n';
f = 1;
break;
}
if (l < r && lca(a[l], a[l + 1]) == v) {
cout << l + 1 << ' ' << l + 2 << '\n';
f = 1;
break;
}
++l;
}
if (!f) {
cout << "-1 -1\n";
}
}
else {
int i, val; cin >> i >> val;
a[--i] = --val;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//int _; cin >> _; while (_--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
212 KB |
n=100 |
4 |
Correct |
0 ms |
212 KB |
n=100 |
5 |
Correct |
0 ms |
212 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
212 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
212 KB |
n=100 |
10 |
Correct |
0 ms |
212 KB |
n=100 |
11 |
Correct |
0 ms |
212 KB |
n=100 |
12 |
Correct |
0 ms |
212 KB |
n=100 |
13 |
Correct |
0 ms |
212 KB |
n=100 |
14 |
Correct |
1 ms |
212 KB |
n=100 |
15 |
Correct |
1 ms |
212 KB |
n=100 |
16 |
Correct |
0 ms |
212 KB |
n=100 |
17 |
Correct |
1 ms |
212 KB |
n=100 |
18 |
Correct |
0 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
212 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
340 KB |
n=100 |
22 |
Correct |
0 ms |
212 KB |
n=100 |
23 |
Correct |
0 ms |
212 KB |
n=100 |
24 |
Correct |
1 ms |
212 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
212 KB |
n=100 |
4 |
Correct |
0 ms |
212 KB |
n=100 |
5 |
Correct |
0 ms |
212 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
212 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
212 KB |
n=100 |
10 |
Correct |
0 ms |
212 KB |
n=100 |
11 |
Correct |
0 ms |
212 KB |
n=100 |
12 |
Correct |
0 ms |
212 KB |
n=100 |
13 |
Correct |
0 ms |
212 KB |
n=100 |
14 |
Correct |
1 ms |
212 KB |
n=100 |
15 |
Correct |
1 ms |
212 KB |
n=100 |
16 |
Correct |
0 ms |
212 KB |
n=100 |
17 |
Correct |
1 ms |
212 KB |
n=100 |
18 |
Correct |
0 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
212 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
340 KB |
n=100 |
22 |
Correct |
0 ms |
212 KB |
n=100 |
23 |
Correct |
0 ms |
212 KB |
n=100 |
24 |
Correct |
1 ms |
212 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
212 KB |
n=100 |
4 |
Correct |
0 ms |
212 KB |
n=100 |
5 |
Correct |
0 ms |
212 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
212 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
212 KB |
n=100 |
10 |
Correct |
0 ms |
212 KB |
n=100 |
11 |
Correct |
0 ms |
212 KB |
n=100 |
12 |
Correct |
0 ms |
212 KB |
n=100 |
13 |
Correct |
0 ms |
212 KB |
n=100 |
14 |
Correct |
1 ms |
212 KB |
n=100 |
15 |
Correct |
1 ms |
212 KB |
n=100 |
16 |
Correct |
0 ms |
212 KB |
n=100 |
17 |
Correct |
1 ms |
212 KB |
n=100 |
18 |
Correct |
0 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
212 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
340 KB |
n=100 |
22 |
Correct |
0 ms |
212 KB |
n=100 |
23 |
Correct |
0 ms |
212 KB |
n=100 |
24 |
Correct |
1 ms |
212 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=5 |
2 |
Correct |
0 ms |
340 KB |
n=100 |
3 |
Correct |
1 ms |
212 KB |
n=100 |
4 |
Correct |
0 ms |
212 KB |
n=100 |
5 |
Correct |
0 ms |
212 KB |
n=100 |
6 |
Correct |
1 ms |
340 KB |
n=100 |
7 |
Correct |
1 ms |
212 KB |
n=100 |
8 |
Correct |
1 ms |
340 KB |
n=100 |
9 |
Correct |
1 ms |
212 KB |
n=100 |
10 |
Correct |
0 ms |
212 KB |
n=100 |
11 |
Correct |
0 ms |
212 KB |
n=100 |
12 |
Correct |
0 ms |
212 KB |
n=100 |
13 |
Correct |
0 ms |
212 KB |
n=100 |
14 |
Correct |
1 ms |
212 KB |
n=100 |
15 |
Correct |
1 ms |
212 KB |
n=100 |
16 |
Correct |
0 ms |
212 KB |
n=100 |
17 |
Correct |
1 ms |
212 KB |
n=100 |
18 |
Correct |
0 ms |
340 KB |
n=100 |
19 |
Correct |
0 ms |
212 KB |
n=100 |
20 |
Correct |
1 ms |
340 KB |
n=100 |
21 |
Correct |
0 ms |
340 KB |
n=100 |
22 |
Correct |
0 ms |
212 KB |
n=100 |
23 |
Correct |
0 ms |
212 KB |
n=100 |
24 |
Correct |
1 ms |
212 KB |
n=100 |
25 |
Correct |
0 ms |
340 KB |
n=100 |
26 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
27 |
Halted |
0 ms |
0 KB |
- |