This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 7 ;
int n , t , m, q;
vector<int> adj[N] ;
vector<int> path;
int st[N] , en[N] ;
int a[N];
int col[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()
{
/// freopen("in.in" , "r" , stdin) ;
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;
int color = 0 ;
int ls = 0 , rs = 0 ;
memset(col , -1 , sizeof col);
for(int i = l+1 ; i<= r-1 ; i++)
{
if(ls==rs)
color++ ;
col[path[i]] = color ;
if( i==st[path[i]] )
ls++;
else rs++;
}
if(a[A-1]==C)
{
nodeA = A-1 ;
nodeB = A-1 ;
}
else
for(int i = A ; i<= B-1 ; i++)
{
if(col[a[i] ] != col[a[i-1]] && col[a[i]]!=-1 && col[a[i-1]]!=-1)
{
nodeA = i-1 ;
nodeB = i ;
break;
}
if(a[i]==C)
{
nodeA = i ;
nodeB = i ;
break;
}
}
cout<<nodeA+1<<" " <<nodeB+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... |