#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 7 ;
int n , t , m, q;
vector<int> adj[N] ;
vector<int> path;
int st[N] , en[N] ;
int a[N] , lcaA[N];
int col[N] , up[N][24];
int isp(int x , int y )
{
return (st[y]>=st[x] && en[y] <=en[x]);
}
void dfs(int x , int p)
{
st[x] = t++ ;
path.push_back(x);
up[x][0] = p ;
for(int i = 1 ; i < 24 ; i++)
up[x][i] = up[ up[x][i-1] ][i-1];
for(auto u : adj[x])
{
if(u==p)
continue;
dfs(u , x) ;
}
en[x] = t++;
path.push_back(x) ;
}
bool inside(int L, int R , int l , int r)
{
return (l>=L && l<=R && r>=L && r<=R);
}
int lca(int x , int y)
{
if(isp(x , y))
return x ;
if(isp(y , x))
return y ;
for(int i = 23 ; i>=0 ; i--)
{
if(!isp(up[x][i] , y))
x = up[x][i] ;
}
return up[x][0] ;
}
int main()
{
//freopen("in.in" , "r" , stdin) ;
cin>>n>>m>>q;
for(int i = 0 ; i < n-1 ; i++)
{
int a, b ;
cin>>a>>b ;
adj[a].push_back(b) ;
adj[b].push_back(a) ;
}
dfs(1 , 1) ;
for(int i = 0 ; i<m ; i++)
{
cin>>a[i] ;
if(i)
lcaA[i] = lca(a[i] , a[i-1] ) ;
}
while(q--)
{
int idx , A , B;
cin>>idx>>A>>B ;
if(idx==1)
{
a[A-1] = B;
if(A>1)
lcaA[A-1] = lca(a[A-1] , lcaA[A-2]) ;
if(A<m)
lcaA[A] = lca(a[A] , a[A-1]) ;
}
else
{
int C;
cin>>C ;
int l = st[C] , r = en[C] ;
int nodeA = -2 , nodeB = -2;
if(a[A-1]==C)
nodeA = nodeB = A-1 ;
for(int i = A ; i<=B-1 ;i++)
{
if(lca(a[i] , a[i-1])==C)
{
nodeA = i-1 ;
nodeB = i;
break;
}
if(a[i]==C)
{
nodeA = i ;
nodeB = i ;
break;
}
}
cout<<nodeA+1<<" " <<nodeB+1<<"\n" ;
}
}
return 0 ;
}
Compilation message
treearray.cpp: In function 'int main()':
treearray.cpp:92:17: warning: unused variable 'l' [-Wunused-variable]
int l = st[C] , r = en[C] ;
^
treearray.cpp:92:29: warning: unused variable 'r' [-Wunused-variable]
int l = st[C] , r = en[C] ;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
n=5 |
2 |
Correct |
8 ms |
4984 KB |
n=100 |
3 |
Correct |
8 ms |
5112 KB |
n=100 |
4 |
Correct |
9 ms |
5112 KB |
n=100 |
5 |
Correct |
8 ms |
4984 KB |
n=100 |
6 |
Correct |
8 ms |
4984 KB |
n=100 |
7 |
Correct |
9 ms |
4984 KB |
n=100 |
8 |
Correct |
8 ms |
4984 KB |
n=100 |
9 |
Correct |
8 ms |
5112 KB |
n=100 |
10 |
Correct |
8 ms |
4984 KB |
n=100 |
11 |
Correct |
8 ms |
5112 KB |
n=100 |
12 |
Correct |
8 ms |
4984 KB |
n=100 |
13 |
Correct |
8 ms |
5112 KB |
n=100 |
14 |
Correct |
10 ms |
4988 KB |
n=100 |
15 |
Correct |
8 ms |
4984 KB |
n=100 |
16 |
Correct |
8 ms |
5116 KB |
n=100 |
17 |
Correct |
8 ms |
5112 KB |
n=100 |
18 |
Correct |
8 ms |
4984 KB |
n=100 |
19 |
Correct |
8 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
4984 KB |
n=100 |
21 |
Correct |
8 ms |
5112 KB |
n=100 |
22 |
Correct |
7 ms |
4984 KB |
n=100 |
23 |
Correct |
7 ms |
4984 KB |
n=100 |
24 |
Correct |
8 ms |
4984 KB |
n=100 |
25 |
Correct |
8 ms |
5112 KB |
n=100 |
26 |
Correct |
8 ms |
4984 KB |
n=12 |
27 |
Correct |
8 ms |
4856 KB |
n=100 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
n=5 |
2 |
Correct |
8 ms |
4984 KB |
n=100 |
3 |
Correct |
8 ms |
5112 KB |
n=100 |
4 |
Correct |
9 ms |
5112 KB |
n=100 |
5 |
Correct |
8 ms |
4984 KB |
n=100 |
6 |
Correct |
8 ms |
4984 KB |
n=100 |
7 |
Correct |
9 ms |
4984 KB |
n=100 |
8 |
Correct |
8 ms |
4984 KB |
n=100 |
9 |
Correct |
8 ms |
5112 KB |
n=100 |
10 |
Correct |
8 ms |
4984 KB |
n=100 |
11 |
Correct |
8 ms |
5112 KB |
n=100 |
12 |
Correct |
8 ms |
4984 KB |
n=100 |
13 |
Correct |
8 ms |
5112 KB |
n=100 |
14 |
Correct |
10 ms |
4988 KB |
n=100 |
15 |
Correct |
8 ms |
4984 KB |
n=100 |
16 |
Correct |
8 ms |
5116 KB |
n=100 |
17 |
Correct |
8 ms |
5112 KB |
n=100 |
18 |
Correct |
8 ms |
4984 KB |
n=100 |
19 |
Correct |
8 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
4984 KB |
n=100 |
21 |
Correct |
8 ms |
5112 KB |
n=100 |
22 |
Correct |
7 ms |
4984 KB |
n=100 |
23 |
Correct |
7 ms |
4984 KB |
n=100 |
24 |
Correct |
8 ms |
4984 KB |
n=100 |
25 |
Correct |
8 ms |
5112 KB |
n=100 |
26 |
Correct |
8 ms |
4984 KB |
n=12 |
27 |
Correct |
8 ms |
4856 KB |
n=100 |
28 |
Correct |
9 ms |
5116 KB |
n=500 |
29 |
Correct |
9 ms |
5112 KB |
n=500 |
30 |
Correct |
10 ms |
5116 KB |
n=500 |
31 |
Correct |
10 ms |
5112 KB |
n=500 |
32 |
Correct |
10 ms |
5112 KB |
n=500 |
33 |
Correct |
11 ms |
5112 KB |
n=500 |
34 |
Correct |
9 ms |
5112 KB |
n=500 |
35 |
Correct |
13 ms |
5112 KB |
n=500 |
36 |
Correct |
30 ms |
5112 KB |
n=500 |
37 |
Correct |
30 ms |
5112 KB |
n=500 |
38 |
Correct |
30 ms |
5112 KB |
n=500 |
39 |
Correct |
20 ms |
5112 KB |
n=500 |
40 |
Correct |
19 ms |
5112 KB |
n=500 |
41 |
Correct |
19 ms |
5112 KB |
n=500 |
42 |
Correct |
19 ms |
5112 KB |
n=500 |
43 |
Correct |
18 ms |
5112 KB |
n=500 |
44 |
Correct |
19 ms |
5112 KB |
n=500 |
45 |
Correct |
9 ms |
5112 KB |
n=500 |
46 |
Correct |
9 ms |
5112 KB |
n=500 |
47 |
Correct |
9 ms |
5112 KB |
n=500 |
48 |
Correct |
10 ms |
5112 KB |
n=500 |
49 |
Correct |
9 ms |
5112 KB |
n=500 |
50 |
Correct |
14 ms |
5112 KB |
n=500 |
51 |
Correct |
11 ms |
5112 KB |
n=500 |
52 |
Correct |
9 ms |
5112 KB |
n=500 |
53 |
Correct |
12 ms |
5112 KB |
n=500 |
54 |
Correct |
10 ms |
5112 KB |
n=500 |
55 |
Correct |
9 ms |
5112 KB |
n=278 |
56 |
Correct |
10 ms |
5112 KB |
n=500 |
57 |
Correct |
9 ms |
5112 KB |
n=500 |
58 |
Correct |
25 ms |
5112 KB |
n=500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
n=5 |
2 |
Correct |
8 ms |
4984 KB |
n=100 |
3 |
Correct |
8 ms |
5112 KB |
n=100 |
4 |
Correct |
9 ms |
5112 KB |
n=100 |
5 |
Correct |
8 ms |
4984 KB |
n=100 |
6 |
Correct |
8 ms |
4984 KB |
n=100 |
7 |
Correct |
9 ms |
4984 KB |
n=100 |
8 |
Correct |
8 ms |
4984 KB |
n=100 |
9 |
Correct |
8 ms |
5112 KB |
n=100 |
10 |
Correct |
8 ms |
4984 KB |
n=100 |
11 |
Correct |
8 ms |
5112 KB |
n=100 |
12 |
Correct |
8 ms |
4984 KB |
n=100 |
13 |
Correct |
8 ms |
5112 KB |
n=100 |
14 |
Correct |
10 ms |
4988 KB |
n=100 |
15 |
Correct |
8 ms |
4984 KB |
n=100 |
16 |
Correct |
8 ms |
5116 KB |
n=100 |
17 |
Correct |
8 ms |
5112 KB |
n=100 |
18 |
Correct |
8 ms |
4984 KB |
n=100 |
19 |
Correct |
8 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
4984 KB |
n=100 |
21 |
Correct |
8 ms |
5112 KB |
n=100 |
22 |
Correct |
7 ms |
4984 KB |
n=100 |
23 |
Correct |
7 ms |
4984 KB |
n=100 |
24 |
Correct |
8 ms |
4984 KB |
n=100 |
25 |
Correct |
8 ms |
5112 KB |
n=100 |
26 |
Correct |
8 ms |
4984 KB |
n=12 |
27 |
Correct |
8 ms |
4856 KB |
n=100 |
28 |
Correct |
9 ms |
5116 KB |
n=500 |
29 |
Correct |
9 ms |
5112 KB |
n=500 |
30 |
Correct |
10 ms |
5116 KB |
n=500 |
31 |
Correct |
10 ms |
5112 KB |
n=500 |
32 |
Correct |
10 ms |
5112 KB |
n=500 |
33 |
Correct |
11 ms |
5112 KB |
n=500 |
34 |
Correct |
9 ms |
5112 KB |
n=500 |
35 |
Correct |
13 ms |
5112 KB |
n=500 |
36 |
Correct |
30 ms |
5112 KB |
n=500 |
37 |
Correct |
30 ms |
5112 KB |
n=500 |
38 |
Correct |
30 ms |
5112 KB |
n=500 |
39 |
Correct |
20 ms |
5112 KB |
n=500 |
40 |
Correct |
19 ms |
5112 KB |
n=500 |
41 |
Correct |
19 ms |
5112 KB |
n=500 |
42 |
Correct |
19 ms |
5112 KB |
n=500 |
43 |
Correct |
18 ms |
5112 KB |
n=500 |
44 |
Correct |
19 ms |
5112 KB |
n=500 |
45 |
Correct |
9 ms |
5112 KB |
n=500 |
46 |
Correct |
9 ms |
5112 KB |
n=500 |
47 |
Correct |
9 ms |
5112 KB |
n=500 |
48 |
Correct |
10 ms |
5112 KB |
n=500 |
49 |
Correct |
9 ms |
5112 KB |
n=500 |
50 |
Correct |
14 ms |
5112 KB |
n=500 |
51 |
Correct |
11 ms |
5112 KB |
n=500 |
52 |
Correct |
9 ms |
5112 KB |
n=500 |
53 |
Correct |
12 ms |
5112 KB |
n=500 |
54 |
Correct |
10 ms |
5112 KB |
n=500 |
55 |
Correct |
9 ms |
5112 KB |
n=278 |
56 |
Correct |
10 ms |
5112 KB |
n=500 |
57 |
Correct |
9 ms |
5112 KB |
n=500 |
58 |
Correct |
25 ms |
5112 KB |
n=500 |
59 |
Correct |
15 ms |
5368 KB |
n=2000 |
60 |
Correct |
18 ms |
5496 KB |
n=2000 |
61 |
Correct |
39 ms |
5496 KB |
n=2000 |
62 |
Correct |
37 ms |
5368 KB |
n=2000 |
63 |
Correct |
16 ms |
5368 KB |
n=2000 |
64 |
Correct |
39 ms |
5368 KB |
n=2000 |
65 |
Correct |
15 ms |
5368 KB |
n=2000 |
66 |
Correct |
28 ms |
5368 KB |
n=2000 |
67 |
Correct |
18 ms |
5368 KB |
n=2000 |
68 |
Correct |
37 ms |
5368 KB |
n=2000 |
69 |
Correct |
340 ms |
5368 KB |
n=2000 |
70 |
Correct |
342 ms |
5504 KB |
n=2000 |
71 |
Correct |
340 ms |
5368 KB |
n=2000 |
72 |
Correct |
180 ms |
5368 KB |
n=2000 |
73 |
Correct |
180 ms |
5368 KB |
n=2000 |
74 |
Correct |
14 ms |
5368 KB |
n=1844 |
75 |
Correct |
184 ms |
5532 KB |
n=2000 |
76 |
Correct |
177 ms |
5408 KB |
n=2000 |
77 |
Correct |
181 ms |
5368 KB |
n=2000 |
78 |
Correct |
186 ms |
5496 KB |
n=2000 |
79 |
Correct |
15 ms |
5372 KB |
n=2000 |
80 |
Correct |
22 ms |
5368 KB |
n=2000 |
81 |
Correct |
34 ms |
5368 KB |
n=2000 |
82 |
Correct |
15 ms |
5368 KB |
n=2000 |
83 |
Correct |
27 ms |
5368 KB |
n=2000 |
84 |
Correct |
100 ms |
5368 KB |
n=2000 |
85 |
Correct |
64 ms |
5368 KB |
n=2000 |
86 |
Correct |
74 ms |
5368 KB |
n=2000 |
87 |
Correct |
109 ms |
5368 KB |
n=2000 |
88 |
Correct |
30 ms |
5496 KB |
n=2000 |
89 |
Correct |
28 ms |
5496 KB |
n=2000 |
90 |
Correct |
22 ms |
5368 KB |
n=2000 |
91 |
Correct |
268 ms |
5368 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
n=5 |
2 |
Correct |
8 ms |
4984 KB |
n=100 |
3 |
Correct |
8 ms |
5112 KB |
n=100 |
4 |
Correct |
9 ms |
5112 KB |
n=100 |
5 |
Correct |
8 ms |
4984 KB |
n=100 |
6 |
Correct |
8 ms |
4984 KB |
n=100 |
7 |
Correct |
9 ms |
4984 KB |
n=100 |
8 |
Correct |
8 ms |
4984 KB |
n=100 |
9 |
Correct |
8 ms |
5112 KB |
n=100 |
10 |
Correct |
8 ms |
4984 KB |
n=100 |
11 |
Correct |
8 ms |
5112 KB |
n=100 |
12 |
Correct |
8 ms |
4984 KB |
n=100 |
13 |
Correct |
8 ms |
5112 KB |
n=100 |
14 |
Correct |
10 ms |
4988 KB |
n=100 |
15 |
Correct |
8 ms |
4984 KB |
n=100 |
16 |
Correct |
8 ms |
5116 KB |
n=100 |
17 |
Correct |
8 ms |
5112 KB |
n=100 |
18 |
Correct |
8 ms |
4984 KB |
n=100 |
19 |
Correct |
8 ms |
5112 KB |
n=100 |
20 |
Correct |
7 ms |
4984 KB |
n=100 |
21 |
Correct |
8 ms |
5112 KB |
n=100 |
22 |
Correct |
7 ms |
4984 KB |
n=100 |
23 |
Correct |
7 ms |
4984 KB |
n=100 |
24 |
Correct |
8 ms |
4984 KB |
n=100 |
25 |
Correct |
8 ms |
5112 KB |
n=100 |
26 |
Correct |
8 ms |
4984 KB |
n=12 |
27 |
Correct |
8 ms |
4856 KB |
n=100 |
28 |
Correct |
9 ms |
5116 KB |
n=500 |
29 |
Correct |
9 ms |
5112 KB |
n=500 |
30 |
Correct |
10 ms |
5116 KB |
n=500 |
31 |
Correct |
10 ms |
5112 KB |
n=500 |
32 |
Correct |
10 ms |
5112 KB |
n=500 |
33 |
Correct |
11 ms |
5112 KB |
n=500 |
34 |
Correct |
9 ms |
5112 KB |
n=500 |
35 |
Correct |
13 ms |
5112 KB |
n=500 |
36 |
Correct |
30 ms |
5112 KB |
n=500 |
37 |
Correct |
30 ms |
5112 KB |
n=500 |
38 |
Correct |
30 ms |
5112 KB |
n=500 |
39 |
Correct |
20 ms |
5112 KB |
n=500 |
40 |
Correct |
19 ms |
5112 KB |
n=500 |
41 |
Correct |
19 ms |
5112 KB |
n=500 |
42 |
Correct |
19 ms |
5112 KB |
n=500 |
43 |
Correct |
18 ms |
5112 KB |
n=500 |
44 |
Correct |
19 ms |
5112 KB |
n=500 |
45 |
Correct |
9 ms |
5112 KB |
n=500 |
46 |
Correct |
9 ms |
5112 KB |
n=500 |
47 |
Correct |
9 ms |
5112 KB |
n=500 |
48 |
Correct |
10 ms |
5112 KB |
n=500 |
49 |
Correct |
9 ms |
5112 KB |
n=500 |
50 |
Correct |
14 ms |
5112 KB |
n=500 |
51 |
Correct |
11 ms |
5112 KB |
n=500 |
52 |
Correct |
9 ms |
5112 KB |
n=500 |
53 |
Correct |
12 ms |
5112 KB |
n=500 |
54 |
Correct |
10 ms |
5112 KB |
n=500 |
55 |
Correct |
9 ms |
5112 KB |
n=278 |
56 |
Correct |
10 ms |
5112 KB |
n=500 |
57 |
Correct |
9 ms |
5112 KB |
n=500 |
58 |
Correct |
25 ms |
5112 KB |
n=500 |
59 |
Correct |
15 ms |
5368 KB |
n=2000 |
60 |
Correct |
18 ms |
5496 KB |
n=2000 |
61 |
Correct |
39 ms |
5496 KB |
n=2000 |
62 |
Correct |
37 ms |
5368 KB |
n=2000 |
63 |
Correct |
16 ms |
5368 KB |
n=2000 |
64 |
Correct |
39 ms |
5368 KB |
n=2000 |
65 |
Correct |
15 ms |
5368 KB |
n=2000 |
66 |
Correct |
28 ms |
5368 KB |
n=2000 |
67 |
Correct |
18 ms |
5368 KB |
n=2000 |
68 |
Correct |
37 ms |
5368 KB |
n=2000 |
69 |
Correct |
340 ms |
5368 KB |
n=2000 |
70 |
Correct |
342 ms |
5504 KB |
n=2000 |
71 |
Correct |
340 ms |
5368 KB |
n=2000 |
72 |
Correct |
180 ms |
5368 KB |
n=2000 |
73 |
Correct |
180 ms |
5368 KB |
n=2000 |
74 |
Correct |
14 ms |
5368 KB |
n=1844 |
75 |
Correct |
184 ms |
5532 KB |
n=2000 |
76 |
Correct |
177 ms |
5408 KB |
n=2000 |
77 |
Correct |
181 ms |
5368 KB |
n=2000 |
78 |
Correct |
186 ms |
5496 KB |
n=2000 |
79 |
Correct |
15 ms |
5372 KB |
n=2000 |
80 |
Correct |
22 ms |
5368 KB |
n=2000 |
81 |
Correct |
34 ms |
5368 KB |
n=2000 |
82 |
Correct |
15 ms |
5368 KB |
n=2000 |
83 |
Correct |
27 ms |
5368 KB |
n=2000 |
84 |
Correct |
100 ms |
5368 KB |
n=2000 |
85 |
Correct |
64 ms |
5368 KB |
n=2000 |
86 |
Correct |
74 ms |
5368 KB |
n=2000 |
87 |
Correct |
109 ms |
5368 KB |
n=2000 |
88 |
Correct |
30 ms |
5496 KB |
n=2000 |
89 |
Correct |
28 ms |
5496 KB |
n=2000 |
90 |
Correct |
22 ms |
5368 KB |
n=2000 |
91 |
Correct |
268 ms |
5368 KB |
n=2000 |
92 |
Correct |
1652 ms |
40160 KB |
n=200000 |
93 |
Execution timed out |
4114 ms |
44044 KB |
Time limit exceeded |
94 |
Halted |
0 ms |
0 KB |
- |