#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,tes,t,f[2009],i,j,tp,k[2009],lf[2009],rg[2009],tim,l,r,lc,msh[2009][11];
vector <int> v[2009];
int bo;
void dfs(int q, int w){
msh[q][0]=w;
for(int h=1; h<=10; h++) msh[q][h]=msh[msh[q][h-1]][h-1];
tim++;
lf[q]=rg[q]=tim;
for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
if((*it)==w) continue;
dfs((*it),q);
if(rg[q]<rg[(*it)]) rg[q]=rg[(*it)];
}
}
bool anc(long long q, long long w){
if(lf[q]<=lf[w]&&rg[q]>=rg[w]) return 1; else return 0;
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>b>>tes;
for(i=1; i<a; i++){
cin>>c>>d;
v[c].push_back(d);
v[d].push_back(c);
}
dfs(1,0);
for(i=1; i<=b; i++) cin>>f[i];
for(t=1; t<=tes; t++){
cin>>tp;
if(tp==1){
cin>>c>>d;
f[c]=d;
continue;
}
cin>>l>>r>>lc;
bo=0;
for(i=l; i<=r; i++){
if(f[i]==lc){
bo=i;
break;
}
if(anc(lc,f[i])==0){
k[i]=0;
}else{
int ff=f[i];
for(j=10; j>=1; j--){
if(msh[ff][j]!=0&&anc(msh[ff][j],lc)==1) ff=msh[ff][j];
}
k[i]=ff;
}
}
if(bo!=0){
cout<<bo<<" "<<bo<<endl;
continue;
}
j=r+1;
pair <pair <int, int> , pair <int, int> > p;
bo=0;
for(i=r; i>=l; i--){
if(k[i]==0){
j=i;
continue;
}
c=0;
if(p.first.second!=k[i]) c=p.first.first; else c=p.second.first;
if(c!=0){
if(j>c){
cout<<i<<" "<<c<<endl;
bo=1;
break;
}
}
//
if(p.first.second!=k[i]){
p.second=p.first;
p.first.first=i;
p.first.second=k[i];
}else{
p.first.first=i;
}
}
if(bo==0){
cout<<"-1 -1"<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
n=5 |
2 |
Incorrect |
2 ms |
376 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
n=5 |
2 |
Incorrect |
2 ms |
376 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
n=5 |
2 |
Incorrect |
2 ms |
376 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
n=5 |
2 |
Incorrect |
2 ms |
376 KB |
Jury has the answer but participant has not |
3 |
Halted |
0 ms |
0 KB |
- |