#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<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<=8;j++)
{
p[sad][j]=p[p[sad][j-1]][j-1];
}
for(int i=0;i<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=8;i>=0;i--)
{
if(deep[p[b][i]]>=deep[a])
{
b=p[b][i];
}
}
if(a==b)
{
return a;
}
for (int i = 8; 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];
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;
}
Compilation message
treearray.cpp: In function 'void go(int, int, int)':
treearray.cpp:16:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[s].size();i++)
~^~~~~~~~~~~~
treearray.cpp: In function 'void mshobelize(int, int)':
treearray.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[sad].size();i++)
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
3 ms |
2680 KB |
n=100 |
3 |
Correct |
3 ms |
2828 KB |
n=100 |
4 |
Correct |
3 ms |
2828 KB |
n=100 |
5 |
Correct |
3 ms |
2828 KB |
n=100 |
6 |
Correct |
4 ms |
2828 KB |
n=100 |
7 |
Correct |
4 ms |
2920 KB |
n=100 |
8 |
Correct |
4 ms |
2920 KB |
n=100 |
9 |
Correct |
3 ms |
2920 KB |
n=100 |
10 |
Correct |
4 ms |
2920 KB |
n=100 |
11 |
Correct |
4 ms |
2920 KB |
n=100 |
12 |
Correct |
3 ms |
2920 KB |
n=100 |
13 |
Correct |
3 ms |
2920 KB |
n=100 |
14 |
Correct |
4 ms |
3020 KB |
n=100 |
15 |
Incorrect |
3 ms |
3020 KB |
Jury has the answer but participant has not |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
3 ms |
2680 KB |
n=100 |
3 |
Correct |
3 ms |
2828 KB |
n=100 |
4 |
Correct |
3 ms |
2828 KB |
n=100 |
5 |
Correct |
3 ms |
2828 KB |
n=100 |
6 |
Correct |
4 ms |
2828 KB |
n=100 |
7 |
Correct |
4 ms |
2920 KB |
n=100 |
8 |
Correct |
4 ms |
2920 KB |
n=100 |
9 |
Correct |
3 ms |
2920 KB |
n=100 |
10 |
Correct |
4 ms |
2920 KB |
n=100 |
11 |
Correct |
4 ms |
2920 KB |
n=100 |
12 |
Correct |
3 ms |
2920 KB |
n=100 |
13 |
Correct |
3 ms |
2920 KB |
n=100 |
14 |
Correct |
4 ms |
3020 KB |
n=100 |
15 |
Incorrect |
3 ms |
3020 KB |
Jury has the answer but participant has not |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
3 ms |
2680 KB |
n=100 |
3 |
Correct |
3 ms |
2828 KB |
n=100 |
4 |
Correct |
3 ms |
2828 KB |
n=100 |
5 |
Correct |
3 ms |
2828 KB |
n=100 |
6 |
Correct |
4 ms |
2828 KB |
n=100 |
7 |
Correct |
4 ms |
2920 KB |
n=100 |
8 |
Correct |
4 ms |
2920 KB |
n=100 |
9 |
Correct |
3 ms |
2920 KB |
n=100 |
10 |
Correct |
4 ms |
2920 KB |
n=100 |
11 |
Correct |
4 ms |
2920 KB |
n=100 |
12 |
Correct |
3 ms |
2920 KB |
n=100 |
13 |
Correct |
3 ms |
2920 KB |
n=100 |
14 |
Correct |
4 ms |
3020 KB |
n=100 |
15 |
Incorrect |
3 ms |
3020 KB |
Jury has the answer but participant has not |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2680 KB |
n=5 |
2 |
Correct |
3 ms |
2680 KB |
n=100 |
3 |
Correct |
3 ms |
2828 KB |
n=100 |
4 |
Correct |
3 ms |
2828 KB |
n=100 |
5 |
Correct |
3 ms |
2828 KB |
n=100 |
6 |
Correct |
4 ms |
2828 KB |
n=100 |
7 |
Correct |
4 ms |
2920 KB |
n=100 |
8 |
Correct |
4 ms |
2920 KB |
n=100 |
9 |
Correct |
3 ms |
2920 KB |
n=100 |
10 |
Correct |
4 ms |
2920 KB |
n=100 |
11 |
Correct |
4 ms |
2920 KB |
n=100 |
12 |
Correct |
3 ms |
2920 KB |
n=100 |
13 |
Correct |
3 ms |
2920 KB |
n=100 |
14 |
Correct |
4 ms |
3020 KB |
n=100 |
15 |
Incorrect |
3 ms |
3020 KB |
Jury has the answer but participant has not |
16 |
Halted |
0 ms |
0 KB |
- |