#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
vector<int>adj[200005];
int two[22][200005];
int d[200005];
void dfs(int index, int par){
for(int x=0;x<20;x++){
two[x+1][index]=two[x][two[x][index]];
}
for(auto it:adj[index]){
if(it==par) continue;
d[it]=d[index]+1;
two[0][it]=index;
dfs(it,index);
}
}
int lca(int a, int b){
if(d[a]>d[b]) swap(a,b);
int diff=d[b]-d[a];
for(int x=0;x<20;x++){
if(diff&(1<<x)){
b=two[x][b];
}
}
if(a==b) return a;
for(int x=19;x>=0;x--){
if(two[x][a]!=two[x][b]){
a=two[x][a];
b=two[x][b];
}
}
return two[0][a];
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
int temp,temp2;
for(int x=0;x<n-1;x++){
cin >> temp >> temp2;
adj[temp].push_back(temp2);
adj[temp2].push_back(temp);
}
dfs(1,-1);
int arr[m+5];
set<int>se[n+5];
set<int>se2[n+5];
for(int x=1;x<=m;x++){
cin >> arr[x];
if(x>1){
se[lca(arr[x],arr[x-1])].insert(x);
}
se2[arr[x]].insert(x);
}
int temp3,temp4;
for(int x=0;x<q;x++){
cin >> temp;
if(temp==1){
cin >> temp2 >> temp3;
se2[arr[temp2]].erase(temp2);
if(temp2<n){
se[lca(arr[temp2],arr[temp2+1])].erase(temp2+1);
}
if(temp2>1){
se[lca(arr[temp2],arr[temp2-1])].erase(temp2);
}
arr[temp2]=temp3;
se2[arr[temp2]].insert(temp2);
if(temp2<n){
se[lca(arr[temp2],arr[temp2+1])].insert(temp2+1);
}
if(temp2>1){
se[lca(arr[temp2],arr[temp2-1])].insert(temp2);
}
}
else{
cin >> temp2 >> temp3 >> temp4;
auto it=se2[temp4].lower_bound(temp2);
auto it2=se[temp4].upper_bound(temp2);
if(it!=se2[temp4].end()&&*it<=temp3){
cout << *it << " " << *it << "\n";
}
else if(it2!=se[temp4].end()&&*it2<=temp3){
cout << *it2-1 << " " << *it2 << "\n";
}
else cout << -1 << " " << -1 << "\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt","r",stdin);
//freopen("in.txt","w",stdout);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |