This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// tree bends in youth
/// 24 .10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =1e5+ 5;
const ll NN =2e6 + 5;
const ll INF = -1e1;
const ll MOD = 1e9 + 7;
const ll LG = 18;
const ll k = 316;
vector <int> g[N];
int tin[N],tout[N],a[N],cnt,used[N];
int p[N][18];
void dfs(int v){
cnt++;
used[v] = 1;
tin[v] = cnt;
for(int to : g[v]){
if(used[to] == 0){
p[to][0] = v;
dfs(to);
}
}
tout[v] = cnt;
}
bool upper(int x,int y){
if(tin[x] <= tin[y] && tout[x] >= tout[y])return 1;
else return 0;
}
int lca(int x,int y){
if(upper(x,y) == 1){
return x;
}
if(upper(y,x) == 1){
return y;
}
for(int j = 16;j >= 0;j--){
int h = p[x][j];
if(upper(h,y) == 0){
x = h;
}
}
return p[x][0];
}
void solve(){
int n,m,q;
cin >> n >> m >> q;
for(int i = 1;i < n;i++){
int u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
p[1][0] = 1;
dfs(1);
for(int i = 1;i <= 16;i++){
for(int j = 1;j <= n;j++){
p[j][i] = p[p[j][i - 1]][i - 1];
}
}
cout << '\n';
for(int i = 1;i <= m;i++){
cin >> a[i];
}
bool was = 1;
while(q--){
int tp,l,r,x;
cin >> tp >> l >> r;
if(tp == 1){
a[l] = r;
}
else{
cin >> x;
bool ok = 0;
for(int j = l;j <= r;j++){
int lc = a[j];
if(lc == x){
cout << j << " " << j << '\n';
ok = 1;
break;
}
int i = j + 1;
while(i <= r){
int lcc= lca(lc,a[i]);
if(lcc == x){
cout << j << ' ' << i << '\n';
ok = 1;
break;
}
lc = lcc;
i++;
}
if(ok)break;
}
if(!ok)cout << "-1 -1\n";
was = 0;
}
}
}
main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll abd= 1;
// cin >> abd;
for(ll i = 1;i <= abd;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message (stderr)
treearray.cpp: In function 'void solve()':
treearray.cpp:73:10: warning: variable 'was' set but not used [-Wunused-but-set-variable]
73 | bool was = 1;
| ^~~
treearray.cpp: At global scope:
treearray.cpp:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
109 | main (){
| ^~~~
# | 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... |