#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 2 * 1e5 + 100, M = 500 + 10, len = 315, inf = 1e18;
const ll mod = 998244353;
ll um(ll a, ll b){
return (1LL * a * b) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
ll bp(ll x, ll step){
ll res = 1;
while(step){
if(step & 1) res = um(res, x);
x = um(x, x);
step /= 2;
}
return res;
}
ll inv(ll x){
return bp(x, mod - 2);
}
int tin[N], tout[N], timer, a[N];
vector <int> q[N];
bool was;
int from, to;
void dfs(int v, int p = -1){
tin[v] = ++timer;
for(auto u : q[v]){
if(u == p) continue;
dfs(u, v);
}
tout[v] = timer;
}
void check(int mn, int mx, int x){
if(mn == INT_MAX) return;
//cout << mn << " "<< mx << endl;
for(auto u : q[x]){
if(tin[u] <= mn && mn <= tout[u] && mx > tout[u]){
if(was == false){
cout << from << " "<< to << endl;
was = true;
}
}
}
}
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
int n, m, qr;
cin >> n >> m >> qr;
for(int i = 0, a, b; i < n - 1; i++){
cin >> a >> b;
q[a].pb(b);
q[b].pb(a);
}
dfs(1);
for(int i = 1; i <= m; i++){
cin >> a[i];
}
for(int i = 0, code, l, r, x, pos; i < qr; i++){
cin >> code;
if(code == 1){
cin >> pos >> x;
a[pos] = x;
} else{
cin >> l >> r >> x;
was = false;
for(int j = l; j <= r; j++){
if(a[j] == x){
was = true;
cout << j << " "<< j << endl;
break;
}
}
for(int j = l; j < r; j++){
from = j;
to = j + 1;
check(min(tin[a[j]], tin[a[j + 1]]), max(tin[a[j]], tin[a[j + 1]]), x);
}
if(was == false) cout << "-1 -1\n";
}
}
return 0;
}
# | 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... |