#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair <int , int>
#define arr3 array <int , 3>
/*
+ array limit ???
+ special case ??? n = 1?
+ time limit ???
*/
using namespace std;
const int INF = 1e9 + 7;
const int maxn = 2e5 + 7;
int n , m , q , jump[20][maxn] , depth[maxn] , a[maxn];
vector <int> g[maxn];
void dfs(int u , int p)
{
for(int v: g[u])
{
if(v == p) continue;
depth[v] = depth[u] + 1;
jump[0][v] = u;
dfs(v , u);
}
}
void build()
{
dfs(1 , 0);
for(int j = 1; j < 20; j++)
{
for(int i =1 ; i <= n; i++)
{
jump[j][i] = jump[j-1][jump[j-1][i]];
}
}
}
int LCA(int u , int v)
{
if(depth[u] > depth[v]) swap(u , v);
for(int i = 19; i >= 0; i--)
{
if(depth[jump[i][v]] >= depth[u])
{
v = jump[i][v];
}
}
if(u == v) return u;
for(int i = 19; i >= 0; i--)
{
if(jump[i][u] != jump[i][v])
{
u = jump[i][u];
v = jump[i][v];
}
}
return jump[0][u];
}
set <pii> ans[maxn];
void solve()
{
cin >> n >> m >> q;
for(int i = 1; i < n; i++)
{
int u , v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
build();
for(int i = 1; i <= m; i++) cin >> a[i];
for(int i = 1; i <= m; i++)
{
ans[a[i]].insert({i , i});
if(i > 1)
{
ans[LCA(a[i] , a[i-1])].insert({i-1 , i});
//cout << LCA(a[i] , a[i-1]) << '\n';
}
}
while(q--)
{
int type; cin >> type;
if(type == 1)
{
int pos , v; cin >> pos >> v;
ans[a[pos]].erase({pos , pos});
ans[v].insert({pos , pos});
if(pos > 1)
{
ans[LCA(a[pos-1] , a[pos])].erase({pos-1 , pos});
ans[LCA(a[pos-1] , v)].insert({pos-1 , pos});
}
if(pos < m)
{
ans[LCA(a[pos] , a[pos+1])].erase({pos , pos+1});
ans[LCA(v , a[pos+1])].insert({pos , pos+1});
}
a[pos] = v;
}
else
{
int l , r , v; cin >> l >> r >> v;
auto it = ans[v].lower_bound({l , l});
if(it != ans[v].end() && (*it).se <= r)
{
cout << (*it).fi << ' ' << (*it).se << '\n';
}
else cout << -1 << ' ' << -1 << '\n';
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
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... |