#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5 + 7 ;
int n , t , m, q;
vector<int> adj[N] ;
vector<int> path;
int st[N] , en[N] ;
int a[N];
void dfs(int x , int p)
{
st[x] = t++ ;
path.push_back(x);
for(auto u : adj[x])
{
if(u==p)
continue;
dfs(u , x) ;
}
en[x] = t++;
path.push_back(x) ;
}
bool inside(int L, int R , int l , int r)
{
return (l>=L && l<=R && r>=L && r<=R);
}
int main()
{
cin>>n>>m>>q;
for(int i = 0 ; i < n-1 ; i++)
{
int a, b ;
cin>>a>>b ;
adj[a].push_back(b) ;
adj[b].push_back(a) ;
}
dfs(1 , 1) ;
for(int i = 0 ; i<m ; i++)
{
cin>>a[i] ;
}
while(q--)
{
int idx , A , B;
cin>>idx>>A>>B ;
if(idx==1)
{
a[A-1] = B;
}
else
{
int C;
cin>>C ;
int l = st[C] , r = en[C] ;
int nodeA = -2 , nodeB = -2;
for(int i = A-1 ; i<=B-1 ;i++)
{
if(nodeA!=-2)
break;
int mL = 1e8 , mR = -1e8 ;
for(int j = i ; j<=B-1 ; j++)
{
mL = min(mL , st[a[j]] ) ;
mR = max(mR , en[a[j]] ) ;
if(mL==l+1 || mR==r-1 || (mL==l&& mR==r) )
{
nodeA = i ;
nodeB = j ;
break;
}
}
}
cout<<nodeA+1<<" " <<nodeB+1<<"\n" ;
}
}
return 0 ;
}
/*
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
n=5 |
2 |
Incorrect |
8 ms |
2680 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
n=5 |
2 |
Incorrect |
8 ms |
2680 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
n=5 |
2 |
Incorrect |
8 ms |
2680 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
n=5 |
2 |
Incorrect |
8 ms |
2680 KB |
Wrong range. |
3 |
Halted |
0 ms |
0 KB |
- |