#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define sz(x) (int)x.size()
#define pii pair<ll,ll>
using namespace std;
const int N=2e5+5;
vector<int>g[N];
int pr[N][20],dep[N]{0};
void dfs(int u,int p,int l){
dep[u]=l;pr[u][0]=p;
for(int i=1;i<20;i++)pr[u][i]=pr[pr[u][i-1]][i-1];
for(auto v:g[u]){
if(v==p)continue;
dfs(v,u,l+1);
}
}
int lca(int a,int b){
if(dep[a]>dep[b])swap(a,b);
for(int i=19;i>=0;i--)if(dep[b]-(1<<i)>=dep[a])b=pr[b][i];
if(a==b)return a;
for(int i=19;i>=0;i--)if(pr[a][i]!=pr[b][i])a=pr[a][i],b=pr[b][i];
return pr[a][0];
}
set<int>d[N],dd[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m,q;cin>>n>>m>>q;
for(int i=1,u,v;i<=n-1;i++)cin>>u>>v,g[u].pb(v),g[v].pb(u);
dfs(1,1,0);int v[m+1];
for(int i=1;i<=n;i++)d[i].insert(1e9),dd[i].insert(1e9);
for(int i=1;i<=m;i++)cin>>v[i],dd[v[i]].insert(i);
for(int i=1;i<=m-1;i++)d[lca(v[i],v[i+1])].insert(i+1);
while(q--){
int o;cin>>o;
if(o==1){
int p,x;cin>>p>>x;
dd[v[p]].erase(dd[v[p]].lower_bound(p));
dd[x].insert(p);
if(p<m){
int u = lca(v[p],v[p+1]);
d[u].erase(d[u].lower_bound(p));
u = lca(x,v[p+1]);
d[u].insert(p+1);
}
if(p>1){
int u = lca(v[p-1],v[p]);
d[u].erase(d[u].lower_bound(p-1));
u = lca(v[p-1],x);
d[u].insert(p);
}v[p]=x;
}
else {
int l,r,v;cin>>l>>r>>v;
auto x = dd[v].lower_bound(l);
if(*x<=r){cout<<*x<<" "<<*x<<'\n';continue;}
x = d[v].lower_bound(l);
if(*x>r)cout<<-1<<" "<<-1<<'\n';
else cout<<(*x)-1<<" "<<(*x)<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25944 KB |
n=5 |
2 |
Incorrect |
5 ms |
25944 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25944 KB |
n=5 |
2 |
Incorrect |
5 ms |
25944 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25944 KB |
n=5 |
2 |
Incorrect |
5 ms |
25944 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25944 KB |
n=5 |
2 |
Incorrect |
5 ms |
25944 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |