이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
//-------------------KarginCode------------------------\\
const int N = 100005;
int a[N];
vector<int> g[N];
int tin[N], tout[N], tim = 0;
int up[N][20];
void dfs(int u, int p) {
tin[u] = tim++;
up[u][0] = p;
for (int v : g[u]) {
if (v != p) dfs(v, u);
}
tout[u] = tim;
}
bool anc(int u, int v) {
return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int x, int y) {
if (anc(x, y)) return x;
if (anc(y, x)) return y;
for (int i = 19;i >= 0;i--) {
if (!anc(up[x][i], y)) x = up[x][i];
}
return up[x][0];
}
void KarginSolve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0;i < n - 1;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];
dfs(1, 1);
for (int j = 1;j < 20;j++) {
for (int i = 1;i <= n;i++) {
up[i][j] = up[up[i][j - 1]][j - 1];
}
}
while (q--) {
int t; cin >> t;
if (t == 1) {
int pos, 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++) {
if (a[i] == v) {
x = y = i;
break;
}
int h = a[i];
for (int j = i + 1;j <= r;j++) {
h = lca(h, a[j]);
if (h == v) {
x = i, y = j;
break;
}
}
if (x != -1) break;
}
cout << x << ' ' << y << '\n';
}
}
}
int main() {
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
treearray.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
treearray.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
treearray.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
treearray.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |