/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
int n, m, q, used[200005],d[200005], tin[200005],a[200005], timer;
vector<int> g[200005],ord;
int t[4 * 200005];
void build(int v,int l,int r)
{
if (l == r)
{
t[v] = ord[l];
return;
}
int m = (l + r) / 2;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
if (d[t[v * 2]] <= d[t[v * 2 + 1]])
t[v] = t[v * 2];
else
t[v] = t[v * 2 + 1];
}
int query(int v,int l,int r,int i,int j)
{
int m = (l + r) / 2;
if (l == i && r == j)
return t[v];
if (j <= m)
return query(v * 2, l, m, i, j);
else if (i >= m + 1)
return query(v * 2 + 1, m + 1, r, i, j);
else
{
int m1 = query(v * 2, l, m, i, m);
int m2 = query(v * 2+1, m + 1, r, m + 1, j);
if (d[m1] <= d[m2])
return m1;
else
return m2;
}
}
void dfs(int v)
{
used[v] = 1;
tin[v] = ord.size();
ord.PB(v);
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
if (used[to])
continue;
d[to] = d[v] + 1;
dfs(to);
ord.PB(v);
}
}
int lca(int a,int b)
{
if (tin[a] > tin[b])
swap(a,b);
int res = query(1, 0, ord.size() - 1, tin[a], tin[b]);
return res;
}
int main()
{
cin >> n >> m >> q;
for (int i = 1; i < n; i++)
{
int a, b;
cin >> a >> b;
g[a].PB(b);
g[b].PB(a);
}
dfs(1);
build(1,0,ord.size()-1);
for (int i = 0; i < m; i++)
cin >> a[i];
for (int ii = 0; ii < q; ii++)
{
int t;
cin >> t;
if (t == 1)
{
int p, v;
cin >> p >> v;
p--;
a[p] = v;
}
else
{
int l, r, v;
pair<int, int> ans = { -1,-1 };
cin >> l >> r >> v;
l--;
r--;
for (int i = l; i <= r; i++)
{
int mn, mx;
mn = mx = i;
for (int j = i; j <= r; j++)
{
if (tin[a[j]] < tin[mn])
mn = j;
if (tin[a[j]] > tin[mx])
mx = j;
if (lca(a[mn], a[mx]) == v)
ans = MP(mn + 1, mx + 1);
}
}
cout << ans.first << " " << ans.second << endl;
}
}
return 0;
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
Compilation message
treearray.cpp: In function 'void dfs(int)':
treearray.cpp:73:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++)
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5084 KB |
n=5 |
2 |
Incorrect |
11 ms |
5244 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5084 KB |
n=5 |
2 |
Incorrect |
11 ms |
5244 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5084 KB |
n=5 |
2 |
Incorrect |
11 ms |
5244 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5084 KB |
n=5 |
2 |
Incorrect |
11 ms |
5244 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |