# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
using namespace std;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
// const int INF = 1e18;
vector < int > adj[N];
set < int > pos[N], pos2[N];
int a[N], tin[N], tout[N], timer = 1, up[N][30], lg;
void dfs( int v, int pr ) {
tin[v] = timer++;
up[v][0] = pr;
for ( int i = 1; i <= lg; i++ ) {
up[v][i] = up[ up[v][i - 1] ][i - 1];
}
for ( auto u: adj[v] ) {
if ( u != pr ) {
dfs(u, v);
}
}
tout[v] = timer;
}
bool is_ancestor( int v, int u ) {
return tin[v] <= tin[u] && tout[v] >= tout[u];
}
int lca( int v, int u ) {
if ( is_ancestor(v, u) ) {
return v;
}
if ( is_ancestor(u, v) ) {
return u;
}
for ( int i = lg; i >= 0; i-- ) {
if ( !is_ancestor(up[v][i], u) ) {
v = up[v][i];
}
}
return up[v][0];
}
int32_t main() {
speed;
int n, m, q;
cin >> n >> m >> q;
lg = log2(n) + 1;
for ( int i = 1; i < n; i++ ) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 1);
for ( int i = 1; i <= m; i++ ) {
cin >> a[i];
}
for ( int i = 1; i < m; i++ ) {
pos[ a[i] ].insert(i);
pos2[ lca( a[i], a[i + 1] ) ].insert(i);
}
for ( int i = 1; i <= q; i++ ) {
int t;
cin >> t;
if ( t == 1 ) {
int p, v;
cin >> p >> v;
pos[ a[p] ].erase(p);
if ( p > 1 ) {
pos2[ lca( a[p - 1], a[p] ) ].erase( p - 1 );
}
if ( p != m ) {
pos2[ lca( a[p], a[p + 1] ) ].erase( p );
}
a[p] = v;
pos[ a[p] ].insert(p);
if ( p > 1 ) {
pos2[ lca( a[p - 1], a[p] ) ].insert(p - 1);
}
if ( p != m ) {
pos2[ lca( a[p], a[p + 1] ) ].insert(p);
}
}
else {
int l, r, v;
cin >> l >> r >> v;
if ( !pos[v].empty() ) {
int j = *pos[v].lower_bound(l);
if ( j <= r ) {
cout << j << ' ' << j << "\n";
continue;
}
}
if ( !pos2[v].empty() ) {
int j = *pos2[v].lower_bound(l);
if ( j < r ) {
cout << j << ' ' << j + 1 << "\n";
continue;
}
}
cout << "-1 -1\n";
}
}
}
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23756 KB |
n=5 |
2 |
Incorrect |
11 ms |
23788 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23756 KB |
n=5 |
2 |
Incorrect |
11 ms |
23788 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23756 KB |
n=5 |
2 |
Incorrect |
11 ms |
23788 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23756 KB |
n=5 |
2 |
Incorrect |
11 ms |
23788 KB |
Wrong output format. |
3 |
Halted |
0 ms |
0 KB |
- |