#include <iostream>
#include <vector>
using namespace std;
int n,k,q,t_out[100003],fin,p[100003][22],deep[100003];
vector<int>a[100003];
int b[100003],t_in[100004],T,x;
bool is_it(int a,int b)
{
return (t_in[a]<=t_in[b])&&(t_out[b]<=t_out[a]);
}
void go(int s,int parent,int DEEP)
{
t_in[s]=++T;
p[s][1]=parent;
deep[s]=DEEP;
for(int i=0;i<(int)a[s].size();i++)
{
if(a[s][i]==parent)continue;
go(a[s][i],s,DEEP+1);
}
t_out[s]=++T;
}
void mshobelize(int Par,int sad)
{
for(int j=2;j<=19;j++)
{
p[sad][j]=p[p[sad][j-1]][j-1];
}
for(int i=0;i<(int)a[sad].size();i++)
{
if(a[sad][i]!=Par)
{
mshobelize(sad,a[sad][i]);
}
}
}
int lca(int a,int b)
{
int A=deep[a];
int B=deep[b];
if(A>B)
{
swap(a,b);
swap(A,B);
}
for(int i=19;i>=0;i--)
{
if(deep[p[b][i]]>=deep[a])
{
b=p[b][i];
}
}
if(a==b)
{
return a;
}
for (int i = 19; i >= 0; i--)
{
if (p[b][i] != p[a][i])
{
b = p[b][i];
a = p[a][i];
}
}
return p[a][1];
}
int u,v,tp;
int main() {ios_base::sync_with_stdio(false);
cin>>n>>k>>q;
for(int i=0;i<n-1;i++)
{
cin>>v>>u;
a[v].push_back(u);
a[u].push_back(v);
}
for(int i=1;i<=k;i++)
{
cin>>b[i];
}
go(1,0,0);
mshobelize(1,1);
t_out[0]=999999999;
while(q--)
{
cin>>tp;
if(tp==1)
{
cin>>u>>v;
b[u]=v;
}
else if(tp==2){
cin>>u>>v>>x;
fin=0;
for(int L=u;!fin&&L<=v;L++)
{
int c=b[L];
for(int R=L;!fin&&R<=v;R++)
{
while(!is_it(c,b[R]))c=p[c][1];
// c=lca(c,b[R]);
if(!is_it(x,c))break;
if(x==c)
{
fin=1;
cout<<L<<" "<<R<<endl;
}
}
}
if(!fin)
{
cout<<"-1 -1"<<endl;
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
4 ms |
2940 KB |
n=100 |
3 |
Correct |
1 ms |
2940 KB |
n=100 |
4 |
Correct |
4 ms |
2940 KB |
n=100 |
5 |
Correct |
4 ms |
2940 KB |
n=100 |
6 |
Correct |
3 ms |
2940 KB |
n=100 |
7 |
Correct |
3 ms |
2940 KB |
n=100 |
8 |
Correct |
3 ms |
2940 KB |
n=100 |
9 |
Correct |
3 ms |
2940 KB |
n=100 |
10 |
Correct |
3 ms |
2940 KB |
n=100 |
11 |
Correct |
4 ms |
2940 KB |
n=100 |
12 |
Correct |
4 ms |
2940 KB |
n=100 |
13 |
Correct |
4 ms |
2940 KB |
n=100 |
14 |
Correct |
4 ms |
2940 KB |
n=100 |
15 |
Correct |
3 ms |
2940 KB |
n=100 |
16 |
Correct |
3 ms |
2940 KB |
n=100 |
17 |
Correct |
4 ms |
2940 KB |
n=100 |
18 |
Correct |
4 ms |
2940 KB |
n=100 |
19 |
Correct |
4 ms |
2940 KB |
n=100 |
20 |
Correct |
4 ms |
2940 KB |
n=100 |
21 |
Correct |
4 ms |
3040 KB |
n=100 |
22 |
Correct |
3 ms |
3040 KB |
n=100 |
23 |
Correct |
4 ms |
3040 KB |
n=100 |
24 |
Correct |
5 ms |
3040 KB |
n=100 |
25 |
Correct |
4 ms |
3040 KB |
n=100 |
26 |
Correct |
4 ms |
3040 KB |
n=12 |
27 |
Correct |
4 ms |
3040 KB |
n=100 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
4 ms |
2940 KB |
n=100 |
3 |
Correct |
1 ms |
2940 KB |
n=100 |
4 |
Correct |
4 ms |
2940 KB |
n=100 |
5 |
Correct |
4 ms |
2940 KB |
n=100 |
6 |
Correct |
3 ms |
2940 KB |
n=100 |
7 |
Correct |
3 ms |
2940 KB |
n=100 |
8 |
Correct |
3 ms |
2940 KB |
n=100 |
9 |
Correct |
3 ms |
2940 KB |
n=100 |
10 |
Correct |
3 ms |
2940 KB |
n=100 |
11 |
Correct |
4 ms |
2940 KB |
n=100 |
12 |
Correct |
4 ms |
2940 KB |
n=100 |
13 |
Correct |
4 ms |
2940 KB |
n=100 |
14 |
Correct |
4 ms |
2940 KB |
n=100 |
15 |
Correct |
3 ms |
2940 KB |
n=100 |
16 |
Correct |
3 ms |
2940 KB |
n=100 |
17 |
Correct |
4 ms |
2940 KB |
n=100 |
18 |
Correct |
4 ms |
2940 KB |
n=100 |
19 |
Correct |
4 ms |
2940 KB |
n=100 |
20 |
Correct |
4 ms |
2940 KB |
n=100 |
21 |
Correct |
4 ms |
3040 KB |
n=100 |
22 |
Correct |
3 ms |
3040 KB |
n=100 |
23 |
Correct |
4 ms |
3040 KB |
n=100 |
24 |
Correct |
5 ms |
3040 KB |
n=100 |
25 |
Correct |
4 ms |
3040 KB |
n=100 |
26 |
Correct |
4 ms |
3040 KB |
n=12 |
27 |
Correct |
4 ms |
3040 KB |
n=100 |
28 |
Correct |
4 ms |
3100 KB |
n=500 |
29 |
Correct |
16 ms |
3112 KB |
n=500 |
30 |
Correct |
11 ms |
3128 KB |
n=500 |
31 |
Correct |
11 ms |
3144 KB |
n=500 |
32 |
Correct |
4 ms |
3160 KB |
n=500 |
33 |
Correct |
8 ms |
3172 KB |
n=500 |
34 |
Correct |
4 ms |
3188 KB |
n=500 |
35 |
Correct |
13 ms |
3200 KB |
n=500 |
36 |
Correct |
5 ms |
3200 KB |
n=500 |
37 |
Correct |
6 ms |
3228 KB |
n=500 |
38 |
Correct |
6 ms |
3368 KB |
n=500 |
39 |
Correct |
5 ms |
3368 KB |
n=500 |
40 |
Correct |
5 ms |
3368 KB |
n=500 |
41 |
Correct |
6 ms |
3368 KB |
n=500 |
42 |
Correct |
5 ms |
3368 KB |
n=500 |
43 |
Correct |
5 ms |
3368 KB |
n=500 |
44 |
Correct |
5 ms |
3368 KB |
n=500 |
45 |
Correct |
5 ms |
3368 KB |
n=500 |
46 |
Correct |
16 ms |
3368 KB |
n=500 |
47 |
Correct |
12 ms |
3368 KB |
n=500 |
48 |
Correct |
4 ms |
3380 KB |
n=500 |
49 |
Correct |
11 ms |
3392 KB |
n=500 |
50 |
Correct |
5 ms |
3536 KB |
n=500 |
51 |
Correct |
10 ms |
3536 KB |
n=500 |
52 |
Correct |
19 ms |
3536 KB |
n=500 |
53 |
Correct |
6 ms |
3536 KB |
n=500 |
54 |
Correct |
27 ms |
3536 KB |
n=500 |
55 |
Correct |
4 ms |
3552 KB |
n=278 |
56 |
Correct |
140 ms |
3556 KB |
n=500 |
57 |
Correct |
147 ms |
3556 KB |
n=500 |
58 |
Correct |
5 ms |
3556 KB |
n=500 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
4 ms |
2940 KB |
n=100 |
3 |
Correct |
1 ms |
2940 KB |
n=100 |
4 |
Correct |
4 ms |
2940 KB |
n=100 |
5 |
Correct |
4 ms |
2940 KB |
n=100 |
6 |
Correct |
3 ms |
2940 KB |
n=100 |
7 |
Correct |
3 ms |
2940 KB |
n=100 |
8 |
Correct |
3 ms |
2940 KB |
n=100 |
9 |
Correct |
3 ms |
2940 KB |
n=100 |
10 |
Correct |
3 ms |
2940 KB |
n=100 |
11 |
Correct |
4 ms |
2940 KB |
n=100 |
12 |
Correct |
4 ms |
2940 KB |
n=100 |
13 |
Correct |
4 ms |
2940 KB |
n=100 |
14 |
Correct |
4 ms |
2940 KB |
n=100 |
15 |
Correct |
3 ms |
2940 KB |
n=100 |
16 |
Correct |
3 ms |
2940 KB |
n=100 |
17 |
Correct |
4 ms |
2940 KB |
n=100 |
18 |
Correct |
4 ms |
2940 KB |
n=100 |
19 |
Correct |
4 ms |
2940 KB |
n=100 |
20 |
Correct |
4 ms |
2940 KB |
n=100 |
21 |
Correct |
4 ms |
3040 KB |
n=100 |
22 |
Correct |
3 ms |
3040 KB |
n=100 |
23 |
Correct |
4 ms |
3040 KB |
n=100 |
24 |
Correct |
5 ms |
3040 KB |
n=100 |
25 |
Correct |
4 ms |
3040 KB |
n=100 |
26 |
Correct |
4 ms |
3040 KB |
n=12 |
27 |
Correct |
4 ms |
3040 KB |
n=100 |
28 |
Correct |
4 ms |
3100 KB |
n=500 |
29 |
Correct |
16 ms |
3112 KB |
n=500 |
30 |
Correct |
11 ms |
3128 KB |
n=500 |
31 |
Correct |
11 ms |
3144 KB |
n=500 |
32 |
Correct |
4 ms |
3160 KB |
n=500 |
33 |
Correct |
8 ms |
3172 KB |
n=500 |
34 |
Correct |
4 ms |
3188 KB |
n=500 |
35 |
Correct |
13 ms |
3200 KB |
n=500 |
36 |
Correct |
5 ms |
3200 KB |
n=500 |
37 |
Correct |
6 ms |
3228 KB |
n=500 |
38 |
Correct |
6 ms |
3368 KB |
n=500 |
39 |
Correct |
5 ms |
3368 KB |
n=500 |
40 |
Correct |
5 ms |
3368 KB |
n=500 |
41 |
Correct |
6 ms |
3368 KB |
n=500 |
42 |
Correct |
5 ms |
3368 KB |
n=500 |
43 |
Correct |
5 ms |
3368 KB |
n=500 |
44 |
Correct |
5 ms |
3368 KB |
n=500 |
45 |
Correct |
5 ms |
3368 KB |
n=500 |
46 |
Correct |
16 ms |
3368 KB |
n=500 |
47 |
Correct |
12 ms |
3368 KB |
n=500 |
48 |
Correct |
4 ms |
3380 KB |
n=500 |
49 |
Correct |
11 ms |
3392 KB |
n=500 |
50 |
Correct |
5 ms |
3536 KB |
n=500 |
51 |
Correct |
10 ms |
3536 KB |
n=500 |
52 |
Correct |
19 ms |
3536 KB |
n=500 |
53 |
Correct |
6 ms |
3536 KB |
n=500 |
54 |
Correct |
27 ms |
3536 KB |
n=500 |
55 |
Correct |
4 ms |
3552 KB |
n=278 |
56 |
Correct |
140 ms |
3556 KB |
n=500 |
57 |
Correct |
147 ms |
3556 KB |
n=500 |
58 |
Correct |
5 ms |
3556 KB |
n=500 |
59 |
Correct |
7 ms |
3788 KB |
n=2000 |
60 |
Correct |
1205 ms |
3980 KB |
n=2000 |
61 |
Correct |
734 ms |
3980 KB |
n=2000 |
62 |
Correct |
214 ms |
3980 KB |
n=2000 |
63 |
Correct |
7 ms |
3980 KB |
n=2000 |
64 |
Correct |
438 ms |
4192 KB |
n=2000 |
65 |
Correct |
7 ms |
4192 KB |
n=2000 |
66 |
Correct |
1113 ms |
4208 KB |
n=2000 |
67 |
Correct |
11 ms |
4448 KB |
n=2000 |
68 |
Correct |
591 ms |
4448 KB |
n=2000 |
69 |
Correct |
41 ms |
4448 KB |
n=2000 |
70 |
Correct |
42 ms |
4532 KB |
n=2000 |
71 |
Correct |
82 ms |
4532 KB |
n=2000 |
72 |
Correct |
25 ms |
4544 KB |
n=2000 |
73 |
Correct |
28 ms |
4752 KB |
n=2000 |
74 |
Correct |
7 ms |
4752 KB |
n=1844 |
75 |
Correct |
27 ms |
4828 KB |
n=2000 |
76 |
Correct |
25 ms |
4828 KB |
n=2000 |
77 |
Correct |
24 ms |
4828 KB |
n=2000 |
78 |
Correct |
25 ms |
4860 KB |
n=2000 |
79 |
Correct |
7 ms |
4912 KB |
n=2000 |
80 |
Correct |
854 ms |
5088 KB |
n=2000 |
81 |
Correct |
409 ms |
5144 KB |
n=2000 |
82 |
Correct |
6 ms |
5144 KB |
n=2000 |
83 |
Correct |
754 ms |
5248 KB |
n=2000 |
84 |
Correct |
10 ms |
5248 KB |
n=2000 |
85 |
Correct |
275 ms |
5356 KB |
n=2000 |
86 |
Correct |
140 ms |
5404 KB |
n=2000 |
87 |
Correct |
10 ms |
5404 KB |
n=2000 |
88 |
Execution timed out |
4083 ms |
5492 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
4 ms |
2940 KB |
n=100 |
3 |
Correct |
1 ms |
2940 KB |
n=100 |
4 |
Correct |
4 ms |
2940 KB |
n=100 |
5 |
Correct |
4 ms |
2940 KB |
n=100 |
6 |
Correct |
3 ms |
2940 KB |
n=100 |
7 |
Correct |
3 ms |
2940 KB |
n=100 |
8 |
Correct |
3 ms |
2940 KB |
n=100 |
9 |
Correct |
3 ms |
2940 KB |
n=100 |
10 |
Correct |
3 ms |
2940 KB |
n=100 |
11 |
Correct |
4 ms |
2940 KB |
n=100 |
12 |
Correct |
4 ms |
2940 KB |
n=100 |
13 |
Correct |
4 ms |
2940 KB |
n=100 |
14 |
Correct |
4 ms |
2940 KB |
n=100 |
15 |
Correct |
3 ms |
2940 KB |
n=100 |
16 |
Correct |
3 ms |
2940 KB |
n=100 |
17 |
Correct |
4 ms |
2940 KB |
n=100 |
18 |
Correct |
4 ms |
2940 KB |
n=100 |
19 |
Correct |
4 ms |
2940 KB |
n=100 |
20 |
Correct |
4 ms |
2940 KB |
n=100 |
21 |
Correct |
4 ms |
3040 KB |
n=100 |
22 |
Correct |
3 ms |
3040 KB |
n=100 |
23 |
Correct |
4 ms |
3040 KB |
n=100 |
24 |
Correct |
5 ms |
3040 KB |
n=100 |
25 |
Correct |
4 ms |
3040 KB |
n=100 |
26 |
Correct |
4 ms |
3040 KB |
n=12 |
27 |
Correct |
4 ms |
3040 KB |
n=100 |
28 |
Correct |
4 ms |
3100 KB |
n=500 |
29 |
Correct |
16 ms |
3112 KB |
n=500 |
30 |
Correct |
11 ms |
3128 KB |
n=500 |
31 |
Correct |
11 ms |
3144 KB |
n=500 |
32 |
Correct |
4 ms |
3160 KB |
n=500 |
33 |
Correct |
8 ms |
3172 KB |
n=500 |
34 |
Correct |
4 ms |
3188 KB |
n=500 |
35 |
Correct |
13 ms |
3200 KB |
n=500 |
36 |
Correct |
5 ms |
3200 KB |
n=500 |
37 |
Correct |
6 ms |
3228 KB |
n=500 |
38 |
Correct |
6 ms |
3368 KB |
n=500 |
39 |
Correct |
5 ms |
3368 KB |
n=500 |
40 |
Correct |
5 ms |
3368 KB |
n=500 |
41 |
Correct |
6 ms |
3368 KB |
n=500 |
42 |
Correct |
5 ms |
3368 KB |
n=500 |
43 |
Correct |
5 ms |
3368 KB |
n=500 |
44 |
Correct |
5 ms |
3368 KB |
n=500 |
45 |
Correct |
5 ms |
3368 KB |
n=500 |
46 |
Correct |
16 ms |
3368 KB |
n=500 |
47 |
Correct |
12 ms |
3368 KB |
n=500 |
48 |
Correct |
4 ms |
3380 KB |
n=500 |
49 |
Correct |
11 ms |
3392 KB |
n=500 |
50 |
Correct |
5 ms |
3536 KB |
n=500 |
51 |
Correct |
10 ms |
3536 KB |
n=500 |
52 |
Correct |
19 ms |
3536 KB |
n=500 |
53 |
Correct |
6 ms |
3536 KB |
n=500 |
54 |
Correct |
27 ms |
3536 KB |
n=500 |
55 |
Correct |
4 ms |
3552 KB |
n=278 |
56 |
Correct |
140 ms |
3556 KB |
n=500 |
57 |
Correct |
147 ms |
3556 KB |
n=500 |
58 |
Correct |
5 ms |
3556 KB |
n=500 |
59 |
Correct |
7 ms |
3788 KB |
n=2000 |
60 |
Correct |
1205 ms |
3980 KB |
n=2000 |
61 |
Correct |
734 ms |
3980 KB |
n=2000 |
62 |
Correct |
214 ms |
3980 KB |
n=2000 |
63 |
Correct |
7 ms |
3980 KB |
n=2000 |
64 |
Correct |
438 ms |
4192 KB |
n=2000 |
65 |
Correct |
7 ms |
4192 KB |
n=2000 |
66 |
Correct |
1113 ms |
4208 KB |
n=2000 |
67 |
Correct |
11 ms |
4448 KB |
n=2000 |
68 |
Correct |
591 ms |
4448 KB |
n=2000 |
69 |
Correct |
41 ms |
4448 KB |
n=2000 |
70 |
Correct |
42 ms |
4532 KB |
n=2000 |
71 |
Correct |
82 ms |
4532 KB |
n=2000 |
72 |
Correct |
25 ms |
4544 KB |
n=2000 |
73 |
Correct |
28 ms |
4752 KB |
n=2000 |
74 |
Correct |
7 ms |
4752 KB |
n=1844 |
75 |
Correct |
27 ms |
4828 KB |
n=2000 |
76 |
Correct |
25 ms |
4828 KB |
n=2000 |
77 |
Correct |
24 ms |
4828 KB |
n=2000 |
78 |
Correct |
25 ms |
4860 KB |
n=2000 |
79 |
Correct |
7 ms |
4912 KB |
n=2000 |
80 |
Correct |
854 ms |
5088 KB |
n=2000 |
81 |
Correct |
409 ms |
5144 KB |
n=2000 |
82 |
Correct |
6 ms |
5144 KB |
n=2000 |
83 |
Correct |
754 ms |
5248 KB |
n=2000 |
84 |
Correct |
10 ms |
5248 KB |
n=2000 |
85 |
Correct |
275 ms |
5356 KB |
n=2000 |
86 |
Correct |
140 ms |
5404 KB |
n=2000 |
87 |
Correct |
10 ms |
5404 KB |
n=2000 |
88 |
Execution timed out |
4083 ms |
5492 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |