#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m,t;
int a,b;
vector <int> v[200001];
int par[200001][41];
int tin[200001],tout[200001];
int mas[200001];
int M=0;
set <int> s[200001];
set <int> s2[200001];
void go (int u,int p){
par[u][0]=p;
tin[u]=++M;
for (int i=1;i<=30;i++){
par[u][i]=par[par[u][i-1]][i-1];
}
for (int i=0;i<v[u].size();i++){
int node=v[u][i];
if (node!=p){
go(node,u);
}
}
tout[u]=++M;
}
bool is_par(int a,int b){
if (tin[a]<=tin[b]&&tout[b]<=tout[a]){
return true;
}
return false;
}
int lca (int a,int b){
if (tin[a]>tin[b]){
swap (a,b);
}
if (is_par(a,b)){
return a;
}
for (int i=30;i>=1;i--){
if (par[a][i]!=0&&!is_par(par[a][i],b)){
a=par[a][i];
}
}
return par[a][0];
}
main () {
ios::sync_with_stdio(false);
//freopen ("damn.in","r",stdin);
cin>>n>>m>>t;
for (int i=1;i<n;i++){
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
for (int i=1;i<=m;i++){
cin>>mas[i];
}
go (1,0);
for (int i=1;i<m;i++){
s[lca(mas[i],mas[i+1])].insert(i);
}
for (int i=1;i<=m;i++){
s2[mas[i]].insert(i);
}
while (t--){
int c;
cin>>c;
if (c==1){
int x,y;
cin>>x>>y;
if (x!=1) s[lca(mas[x-1],mas[x])].erase(x-1);
if (x!=m) s[lca(mas[x],mas[x+1])].erase(x);
s2[mas[x]].erase(x);
mas[x]=y;
if (x!=1) s[lca(mas[x-1],mas[x])].insert(x-1);
if (x!=m) s[lca(mas[x],mas[x+1])].insert(x);
s2[mas[x]].insert(x);
}
else{
int l,r,v2;
cin>>l>>r>>v2;
set<int>::iterator it,it2;
it=s[v2].lower_bound(l);
//cout<<"WOW"<<l<<" "<<r<<" "<<v<<endl;
it2=s2[v2].lower_bound(l);
int e;
e=*it2;
if (it2!=s2[v2].end()&&e<=r){
cout<<e<<" "<<e<<endl;
continue;
}
if (it!=s[v2].end()){
e=*it;
if (e<r){
cout<<e<<" "<<e+1<<endl;
continue;
}
else{
cout<<-1<<" "<<-1<<endl;
continue;
}
}
cout<<-1<<" "<<-1<<endl;
}
}
return 0;
}
/*
_ _ _ _
| \ | | (_) | |
| \| | _ ___ | | __ ___ ___ _ __ __ _
| . ` | | | / __| | |/ / / __| / _ \ | '_ \ / _` |
| |\ | | | | (__ | < \__ \ | (_) | | | | | | (_| |
|_| \_| |_| \___| |_|\_\ |___/ \___/ |_| |_| \__,_|
*/
Compilation message
treearray.cpp: In function 'void go(int, int)':
treearray.cpp:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[u].size();i++){
~^~~~~~~~~~~~
treearray.cpp: At global scope:
treearray.cpp:53:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
n=5 |
2 |
Incorrect |
25 ms |
24056 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
n=5 |
2 |
Incorrect |
25 ms |
24056 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
n=5 |
2 |
Incorrect |
25 ms |
24056 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
n=5 |
2 |
Incorrect |
25 ms |
24056 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |