#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];
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];
}
set <int> s2[200001];
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;
s[lca(mas[x-1],mas[x])].erase(x-1);
s[lca(mas[x],mas[x+1])].erase(x);
s2[mas[x]].erase(x);
mas[x]=y;
s[lca(mas[x-1],mas[x])].insert(x-1);
s[lca(mas[x],mas[x+1])].insert(x);
s2[mas[x]].insert(x);
}
else{
int l,r,v;
cin>>l>>r>>v;
set<int>::iterator it,it2;
it=s[v].lower_bound(l);
it2=s2[v].lower_bound(l);
if (it2!=s2[v].end()){
cout<<*it2<<" "<<*it2<<endl;
continue;
}
if (it!=s[v].end()){
a=*it;
if (a<r) cout<<a<<" "<<a+1<<endl;
else cout<<"-1 -1"<<endl;
}
else{
cout<<"-1 -1"<<endl;
}
}
}
return 0;
}
/*
_ _ _ _
| \ | | (_) | |
| \| | _ ___ | | __ ___ ___ _ __ __ _
| . ` | | | / __| | |/ / / __| / _ \ | '_ \ / _` |
| |\ | | | | (__ | < \__ \ | (_) | | | | | | (_| |
|_| \_| |_| \___| |_|\_\ |___/ \___/ |_| |_| \__,_|
*/
Compilation message
treearray.cpp: In function 'void go(int, int)':
treearray.cpp:20: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:51:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
n=5 |
2 |
Incorrect |
21 ms |
23936 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
n=5 |
2 |
Incorrect |
21 ms |
23936 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
n=5 |
2 |
Incorrect |
21 ms |
23936 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
23928 KB |
n=5 |
2 |
Incorrect |
21 ms |
23936 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |