#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
struct Lca{
vector<int>adj[N];
int in[N];
int out[N];
int timer=1;
int P[N];
int Log(int n){
int logs[n+1];
logs[1]=0;
for(int i=2;i<=n;i++)logs[i]=logs[i/2]+1;
return logs[n];
}
int up[N][30];
void build(int n){
up[1][0]=1;
for(int i=2;i<=n;i++)up[i][0]=P[i];
for(int i=1;i<=29;i++){
for(int j=1;j<=n;j++){
up[j][i]=up[up[j][i-1]][i-1];
}
}
}
void add(int u,int v){
adj[u].push_back(v);
adj[v].push_back(u);
}
void dfs(int x,int cale){
in[x]=timer++;
P[x]=cale;
for(auto it:adj[x]){
if(it!=cale)dfs(it,x);
}
out[x]=timer;
}
int in_tree(int u,int v){
return in[u]<=in[v]&&out[u]>=out[v];
}
int lca(int u,int v){
if(u==v)return u;
if(in_tree(u,v))return u;
if(in_tree(v,u))return v;
for(int i=29;i>=0;i--){
if(!in_tree(up[u][i],v)){
u=up[u][i];
}
}
return up[u][0];
}
}lca;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
for(int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
lca.add(u,v);
}
lca.dfs(1, 0);
lca.build(n);
vector<int> a(m + 1);
for(int i = 1; i <= m; i++) {
cin >> a[i];
}
while(q--) {
int type;
cin >> type;
if(type == 1) {
int pos, v;
cin >> pos >> v;
a[pos] = v;
}
else {
int l, r, x;
cin >> l >> r >> x;
int l1 = - 1, r1 = - 1;
for(int i = l; i <= r; i++) {
if(a[i] == x) {
l1 = i;
r1 = i;
}
}
for(int i = l; i < r; i++) {
if(lca.lca(a[i], a[i + 1]) == x) {
l1 = i;
r1 = i + 1;
}
}
cout << l1 << " " << r1 << "\n";
}
}
}
# | 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... |