/*
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], tout[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);
}
tout[v] = ord.size();
}
bool upper(int a, int b)
{
return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}
int LCA(int a,int b)
{
if (a == b)
return a;
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;
if (max(q, max(n, m)) > 600)
return 0;
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;
scanf("%d",&t);
if (t == 1)
{
int p, v;
scanf("%d%d", &p,&v);
p--;
a[p] = v;
}
else
{
int L, R, v,l,r;
scanf("%d%d%d", &L, &R,&v);
pair<int, int> ans = MP( -1,-1 );
L--;
R--;
l = L;
int lca=a[l];
for (r = L; r <= R; r++)
{
if (!upper(v, a[r]))
{
l = r + 1;
lca = a[l];
continue;
}
lca = LCA(lca,a[r]);
if (lca == v)
{
ans = MP(l+1,r+1);
break;
}
}
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++)
~~^~~~~~~~~~~~~
treearray.cpp: In function 'int main()':
treearray.cpp:120:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&t);
~~~~~^~~~~~~~~
treearray.cpp:124:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &p,&v);
~~~~~^~~~~~~~~~~~~~~
treearray.cpp:131:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &L, &R,&v);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
n=5 |
2 |
Correct |
5 ms |
5108 KB |
n=100 |
3 |
Correct |
6 ms |
5128 KB |
n=100 |
4 |
Correct |
6 ms |
5128 KB |
n=100 |
5 |
Correct |
5 ms |
5128 KB |
n=100 |
6 |
Correct |
5 ms |
5344 KB |
n=100 |
7 |
Correct |
5 ms |
5344 KB |
n=100 |
8 |
Correct |
5 ms |
5344 KB |
n=100 |
9 |
Correct |
5 ms |
5352 KB |
n=100 |
10 |
Correct |
5 ms |
5352 KB |
n=100 |
11 |
Correct |
5 ms |
5352 KB |
n=100 |
12 |
Correct |
5 ms |
5352 KB |
n=100 |
13 |
Correct |
5 ms |
5352 KB |
n=100 |
14 |
Correct |
5 ms |
5352 KB |
n=100 |
15 |
Correct |
6 ms |
5352 KB |
n=100 |
16 |
Correct |
6 ms |
5372 KB |
n=100 |
17 |
Correct |
6 ms |
5372 KB |
n=100 |
18 |
Correct |
5 ms |
5372 KB |
n=100 |
19 |
Correct |
6 ms |
5372 KB |
n=100 |
20 |
Correct |
6 ms |
5372 KB |
n=100 |
21 |
Correct |
6 ms |
5372 KB |
n=100 |
22 |
Correct |
6 ms |
5372 KB |
n=100 |
23 |
Correct |
6 ms |
5400 KB |
n=100 |
24 |
Correct |
6 ms |
5400 KB |
n=100 |
25 |
Correct |
5 ms |
5400 KB |
n=100 |
26 |
Correct |
5 ms |
5400 KB |
n=12 |
27 |
Correct |
5 ms |
5400 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
n=5 |
2 |
Correct |
5 ms |
5108 KB |
n=100 |
3 |
Correct |
6 ms |
5128 KB |
n=100 |
4 |
Correct |
6 ms |
5128 KB |
n=100 |
5 |
Correct |
5 ms |
5128 KB |
n=100 |
6 |
Correct |
5 ms |
5344 KB |
n=100 |
7 |
Correct |
5 ms |
5344 KB |
n=100 |
8 |
Correct |
5 ms |
5344 KB |
n=100 |
9 |
Correct |
5 ms |
5352 KB |
n=100 |
10 |
Correct |
5 ms |
5352 KB |
n=100 |
11 |
Correct |
5 ms |
5352 KB |
n=100 |
12 |
Correct |
5 ms |
5352 KB |
n=100 |
13 |
Correct |
5 ms |
5352 KB |
n=100 |
14 |
Correct |
5 ms |
5352 KB |
n=100 |
15 |
Correct |
6 ms |
5352 KB |
n=100 |
16 |
Correct |
6 ms |
5372 KB |
n=100 |
17 |
Correct |
6 ms |
5372 KB |
n=100 |
18 |
Correct |
5 ms |
5372 KB |
n=100 |
19 |
Correct |
6 ms |
5372 KB |
n=100 |
20 |
Correct |
6 ms |
5372 KB |
n=100 |
21 |
Correct |
6 ms |
5372 KB |
n=100 |
22 |
Correct |
6 ms |
5372 KB |
n=100 |
23 |
Correct |
6 ms |
5400 KB |
n=100 |
24 |
Correct |
6 ms |
5400 KB |
n=100 |
25 |
Correct |
5 ms |
5400 KB |
n=100 |
26 |
Correct |
5 ms |
5400 KB |
n=12 |
27 |
Correct |
5 ms |
5400 KB |
n=100 |
28 |
Correct |
6 ms |
5412 KB |
n=500 |
29 |
Correct |
8 ms |
5424 KB |
n=500 |
30 |
Correct |
8 ms |
5468 KB |
n=500 |
31 |
Correct |
8 ms |
5484 KB |
n=500 |
32 |
Correct |
7 ms |
5500 KB |
n=500 |
33 |
Correct |
8 ms |
5512 KB |
n=500 |
34 |
Correct |
6 ms |
5528 KB |
n=500 |
35 |
Correct |
8 ms |
5528 KB |
n=500 |
36 |
Correct |
7 ms |
5528 KB |
n=500 |
37 |
Correct |
7 ms |
5560 KB |
n=500 |
38 |
Correct |
7 ms |
5560 KB |
n=500 |
39 |
Correct |
7 ms |
5560 KB |
n=500 |
40 |
Correct |
6 ms |
5560 KB |
n=500 |
41 |
Correct |
6 ms |
5576 KB |
n=500 |
42 |
Correct |
7 ms |
5592 KB |
n=500 |
43 |
Correct |
6 ms |
5604 KB |
n=500 |
44 |
Correct |
6 ms |
5616 KB |
n=500 |
45 |
Correct |
6 ms |
5628 KB |
n=500 |
46 |
Correct |
7 ms |
5640 KB |
n=500 |
47 |
Correct |
8 ms |
5656 KB |
n=500 |
48 |
Correct |
6 ms |
5656 KB |
n=500 |
49 |
Correct |
7 ms |
5728 KB |
n=500 |
50 |
Correct |
6 ms |
5728 KB |
n=500 |
51 |
Correct |
7 ms |
5728 KB |
n=500 |
52 |
Correct |
8 ms |
5728 KB |
n=500 |
53 |
Correct |
7 ms |
5744 KB |
n=500 |
54 |
Correct |
12 ms |
5760 KB |
n=500 |
55 |
Correct |
6 ms |
5772 KB |
n=278 |
56 |
Correct |
19 ms |
5780 KB |
n=500 |
57 |
Correct |
19 ms |
5796 KB |
n=500 |
58 |
Correct |
7 ms |
5804 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
n=5 |
2 |
Correct |
5 ms |
5108 KB |
n=100 |
3 |
Correct |
6 ms |
5128 KB |
n=100 |
4 |
Correct |
6 ms |
5128 KB |
n=100 |
5 |
Correct |
5 ms |
5128 KB |
n=100 |
6 |
Correct |
5 ms |
5344 KB |
n=100 |
7 |
Correct |
5 ms |
5344 KB |
n=100 |
8 |
Correct |
5 ms |
5344 KB |
n=100 |
9 |
Correct |
5 ms |
5352 KB |
n=100 |
10 |
Correct |
5 ms |
5352 KB |
n=100 |
11 |
Correct |
5 ms |
5352 KB |
n=100 |
12 |
Correct |
5 ms |
5352 KB |
n=100 |
13 |
Correct |
5 ms |
5352 KB |
n=100 |
14 |
Correct |
5 ms |
5352 KB |
n=100 |
15 |
Correct |
6 ms |
5352 KB |
n=100 |
16 |
Correct |
6 ms |
5372 KB |
n=100 |
17 |
Correct |
6 ms |
5372 KB |
n=100 |
18 |
Correct |
5 ms |
5372 KB |
n=100 |
19 |
Correct |
6 ms |
5372 KB |
n=100 |
20 |
Correct |
6 ms |
5372 KB |
n=100 |
21 |
Correct |
6 ms |
5372 KB |
n=100 |
22 |
Correct |
6 ms |
5372 KB |
n=100 |
23 |
Correct |
6 ms |
5400 KB |
n=100 |
24 |
Correct |
6 ms |
5400 KB |
n=100 |
25 |
Correct |
5 ms |
5400 KB |
n=100 |
26 |
Correct |
5 ms |
5400 KB |
n=12 |
27 |
Correct |
5 ms |
5400 KB |
n=100 |
28 |
Correct |
6 ms |
5412 KB |
n=500 |
29 |
Correct |
8 ms |
5424 KB |
n=500 |
30 |
Correct |
8 ms |
5468 KB |
n=500 |
31 |
Correct |
8 ms |
5484 KB |
n=500 |
32 |
Correct |
7 ms |
5500 KB |
n=500 |
33 |
Correct |
8 ms |
5512 KB |
n=500 |
34 |
Correct |
6 ms |
5528 KB |
n=500 |
35 |
Correct |
8 ms |
5528 KB |
n=500 |
36 |
Correct |
7 ms |
5528 KB |
n=500 |
37 |
Correct |
7 ms |
5560 KB |
n=500 |
38 |
Correct |
7 ms |
5560 KB |
n=500 |
39 |
Correct |
7 ms |
5560 KB |
n=500 |
40 |
Correct |
6 ms |
5560 KB |
n=500 |
41 |
Correct |
6 ms |
5576 KB |
n=500 |
42 |
Correct |
7 ms |
5592 KB |
n=500 |
43 |
Correct |
6 ms |
5604 KB |
n=500 |
44 |
Correct |
6 ms |
5616 KB |
n=500 |
45 |
Correct |
6 ms |
5628 KB |
n=500 |
46 |
Correct |
7 ms |
5640 KB |
n=500 |
47 |
Correct |
8 ms |
5656 KB |
n=500 |
48 |
Correct |
6 ms |
5656 KB |
n=500 |
49 |
Correct |
7 ms |
5728 KB |
n=500 |
50 |
Correct |
6 ms |
5728 KB |
n=500 |
51 |
Correct |
7 ms |
5728 KB |
n=500 |
52 |
Correct |
8 ms |
5728 KB |
n=500 |
53 |
Correct |
7 ms |
5744 KB |
n=500 |
54 |
Correct |
12 ms |
5760 KB |
n=500 |
55 |
Correct |
6 ms |
5772 KB |
n=278 |
56 |
Correct |
19 ms |
5780 KB |
n=500 |
57 |
Correct |
19 ms |
5796 KB |
n=500 |
58 |
Correct |
7 ms |
5804 KB |
n=500 |
59 |
Incorrect |
5 ms |
5804 KB |
Unexpected end of file - int32 expected |
60 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4984 KB |
n=5 |
2 |
Correct |
5 ms |
5108 KB |
n=100 |
3 |
Correct |
6 ms |
5128 KB |
n=100 |
4 |
Correct |
6 ms |
5128 KB |
n=100 |
5 |
Correct |
5 ms |
5128 KB |
n=100 |
6 |
Correct |
5 ms |
5344 KB |
n=100 |
7 |
Correct |
5 ms |
5344 KB |
n=100 |
8 |
Correct |
5 ms |
5344 KB |
n=100 |
9 |
Correct |
5 ms |
5352 KB |
n=100 |
10 |
Correct |
5 ms |
5352 KB |
n=100 |
11 |
Correct |
5 ms |
5352 KB |
n=100 |
12 |
Correct |
5 ms |
5352 KB |
n=100 |
13 |
Correct |
5 ms |
5352 KB |
n=100 |
14 |
Correct |
5 ms |
5352 KB |
n=100 |
15 |
Correct |
6 ms |
5352 KB |
n=100 |
16 |
Correct |
6 ms |
5372 KB |
n=100 |
17 |
Correct |
6 ms |
5372 KB |
n=100 |
18 |
Correct |
5 ms |
5372 KB |
n=100 |
19 |
Correct |
6 ms |
5372 KB |
n=100 |
20 |
Correct |
6 ms |
5372 KB |
n=100 |
21 |
Correct |
6 ms |
5372 KB |
n=100 |
22 |
Correct |
6 ms |
5372 KB |
n=100 |
23 |
Correct |
6 ms |
5400 KB |
n=100 |
24 |
Correct |
6 ms |
5400 KB |
n=100 |
25 |
Correct |
5 ms |
5400 KB |
n=100 |
26 |
Correct |
5 ms |
5400 KB |
n=12 |
27 |
Correct |
5 ms |
5400 KB |
n=100 |
28 |
Correct |
6 ms |
5412 KB |
n=500 |
29 |
Correct |
8 ms |
5424 KB |
n=500 |
30 |
Correct |
8 ms |
5468 KB |
n=500 |
31 |
Correct |
8 ms |
5484 KB |
n=500 |
32 |
Correct |
7 ms |
5500 KB |
n=500 |
33 |
Correct |
8 ms |
5512 KB |
n=500 |
34 |
Correct |
6 ms |
5528 KB |
n=500 |
35 |
Correct |
8 ms |
5528 KB |
n=500 |
36 |
Correct |
7 ms |
5528 KB |
n=500 |
37 |
Correct |
7 ms |
5560 KB |
n=500 |
38 |
Correct |
7 ms |
5560 KB |
n=500 |
39 |
Correct |
7 ms |
5560 KB |
n=500 |
40 |
Correct |
6 ms |
5560 KB |
n=500 |
41 |
Correct |
6 ms |
5576 KB |
n=500 |
42 |
Correct |
7 ms |
5592 KB |
n=500 |
43 |
Correct |
6 ms |
5604 KB |
n=500 |
44 |
Correct |
6 ms |
5616 KB |
n=500 |
45 |
Correct |
6 ms |
5628 KB |
n=500 |
46 |
Correct |
7 ms |
5640 KB |
n=500 |
47 |
Correct |
8 ms |
5656 KB |
n=500 |
48 |
Correct |
6 ms |
5656 KB |
n=500 |
49 |
Correct |
7 ms |
5728 KB |
n=500 |
50 |
Correct |
6 ms |
5728 KB |
n=500 |
51 |
Correct |
7 ms |
5728 KB |
n=500 |
52 |
Correct |
8 ms |
5728 KB |
n=500 |
53 |
Correct |
7 ms |
5744 KB |
n=500 |
54 |
Correct |
12 ms |
5760 KB |
n=500 |
55 |
Correct |
6 ms |
5772 KB |
n=278 |
56 |
Correct |
19 ms |
5780 KB |
n=500 |
57 |
Correct |
19 ms |
5796 KB |
n=500 |
58 |
Correct |
7 ms |
5804 KB |
n=500 |
59 |
Incorrect |
5 ms |
5804 KB |
Unexpected end of file - int32 expected |
60 |
Halted |
0 ms |
0 KB |
- |