Submission #90588

# Submission time Handle Problem Language Result Execution time Memory
90588 2018-12-22T15:46:39 Z mrtsima22 Birthday gift (IZhO18_treearray) C++17
0 / 100
4 ms 3008 KB
#include <iostream>
#include <vector>
using namespace std;
int n,k,q,t_out[100003],fin,p[100003][22],deep[100003];
vector<int>a[100003];
int ba[100003],t_in[100004],T,x;
bool is_it(int a,int b){
	return (t_in[a]<=t_in[b])&&(t_out[b]<=t_out[a]);
}
void go(int s,int parent,int DEEP){
	t_in[s]=++T;
	p[s][1]=parent;
	deep[s]=DEEP;
	for(int i=0;i<(int)a[s].size();i++){
		if(a[s][i]==parent)continue;
		go(a[s][i],s,DEEP+1);
	}
	t_out[s]=++T;
}
void mshobelize(int Par,int sad){
	for(int j=2;j<=19;j++){
		p[sad][j]=p[p[sad][j-1]][j-1];
	}
	for(int i=0;i<(int)a[sad].size();i++){
		if(a[sad][i]!=Par){
			mshobelize(sad,a[sad][i]);
		}
	}
}
int lca(int a,int b){
	int A=deep[a];
	int B=deep[b];
	if(A>B){
		swap(a,b);
		swap(A,B);
	}
	for(int i=19;i>=0;i--){
		if(deep[p[b][i]]>=deep[a]){
			b=p[b][i];
		}
	}
	if(a==b){
		return a;
	}
    for (int i = 19; i >= 0; i--) {
        if (p[b][i] != p[a][i]) {
            b = p[b][i];       
            a = p[a][i];
        }
    }
    return p[a][1];
}
int u,v,tp;
int main() {ios_base::sync_with_stdio(false);
cin>>n>>k>>q;
for(int i=0;i<n-1;i++){
	cin>>v>>u;
	a[v].push_back(u);
	a[u].push_back(v);
}
for(int i=1;i<=k;i++){
	cin>>ba[i];
}

go(1,0,0);

for(int i=0;i<=19;i++){
	p[1][i]=1;
}

mshobelize(1,1);

/*
for(int i=1;i<=n;i++)
{
	cout<<i<<"----===>";
	for(int j=1;j<=19;j++)
	{
		cout<<p[i][j]<<" ";
	}
	cout<<endl;
}
*/
t_out[0]=999999999;
while(q--){
	cin>>tp;
	if(tp==1)
	{
		cin>>u>>v;
		ba[u]=v;
	}
	else if(tp==2){
	cin>>u>>v>>x;
	fin=0;
		for(int L=u;!fin&&L<v;L++){
			int c=ba[L];
			if(x==c&&fin==0){
				fin=1;
				cout<<L<<" "<<L<<endl;
			}
			int c1=ba[L+1];
				c=lca(c,c1);
			if(x==c1&&fin==0){
				fin=1;
				cout<<L+1<<" "<<L+1<<endl;
			}
//			if(!is_it(x,c))break;
			if(x==c&&fin==0){
				fin=1;
				cout<<L<<" "<<L+1<<endl;
			}
		}
		if(!fin){
			cout<<"-1 -1"<<endl;
		}
	}
	
}
 
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2680 KB n=100
3 Correct 4 ms 2952 KB n=100
4 Correct 4 ms 2952 KB n=100
5 Correct 4 ms 2952 KB n=100
6 Correct 4 ms 2952 KB n=100
7 Correct 4 ms 2952 KB n=100
8 Correct 4 ms 2952 KB n=100
9 Correct 4 ms 2952 KB n=100
10 Correct 3 ms 2952 KB n=100
11 Correct 4 ms 2952 KB n=100
12 Correct 4 ms 2952 KB n=100
13 Correct 4 ms 2952 KB n=100
14 Correct 4 ms 2952 KB n=100
15 Correct 4 ms 3008 KB n=100
16 Incorrect 4 ms 3008 KB Jury has the answer but participant has not
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2680 KB n=100
3 Correct 4 ms 2952 KB n=100
4 Correct 4 ms 2952 KB n=100
5 Correct 4 ms 2952 KB n=100
6 Correct 4 ms 2952 KB n=100
7 Correct 4 ms 2952 KB n=100
8 Correct 4 ms 2952 KB n=100
9 Correct 4 ms 2952 KB n=100
10 Correct 3 ms 2952 KB n=100
11 Correct 4 ms 2952 KB n=100
12 Correct 4 ms 2952 KB n=100
13 Correct 4 ms 2952 KB n=100
14 Correct 4 ms 2952 KB n=100
15 Correct 4 ms 3008 KB n=100
16 Incorrect 4 ms 3008 KB Jury has the answer but participant has not
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2680 KB n=100
3 Correct 4 ms 2952 KB n=100
4 Correct 4 ms 2952 KB n=100
5 Correct 4 ms 2952 KB n=100
6 Correct 4 ms 2952 KB n=100
7 Correct 4 ms 2952 KB n=100
8 Correct 4 ms 2952 KB n=100
9 Correct 4 ms 2952 KB n=100
10 Correct 3 ms 2952 KB n=100
11 Correct 4 ms 2952 KB n=100
12 Correct 4 ms 2952 KB n=100
13 Correct 4 ms 2952 KB n=100
14 Correct 4 ms 2952 KB n=100
15 Correct 4 ms 3008 KB n=100
16 Incorrect 4 ms 3008 KB Jury has the answer but participant has not
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB n=5
2 Correct 4 ms 2680 KB n=100
3 Correct 4 ms 2952 KB n=100
4 Correct 4 ms 2952 KB n=100
5 Correct 4 ms 2952 KB n=100
6 Correct 4 ms 2952 KB n=100
7 Correct 4 ms 2952 KB n=100
8 Correct 4 ms 2952 KB n=100
9 Correct 4 ms 2952 KB n=100
10 Correct 3 ms 2952 KB n=100
11 Correct 4 ms 2952 KB n=100
12 Correct 4 ms 2952 KB n=100
13 Correct 4 ms 2952 KB n=100
14 Correct 4 ms 2952 KB n=100
15 Correct 4 ms 3008 KB n=100
16 Incorrect 4 ms 3008 KB Jury has the answer but participant has not
17 Halted 0 ms 0 KB -