답안 #90580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90580 2018-12-22T15:01:57 Z mrtsima22 Birthday gift (IZhO18_treearray) C++17
컴파일 오류
0 ms 0 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 b[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<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>>b[i];
}
go(1,0,0);
mshobelize(1,1);
t_out[0]=999999999;
while(q--)
{
	cin>>tp;
	if(tp==1)
	{
		cin>>u>>v;
		b[u]=v;
	}
	else if(tp==2){
	cin>>u>>v>>x;
	fin=0;
		for(int L=u;!fin&&L<=v;L++)
		{
			int c=b[L];
			for(int R=L;!fin&&R<=v;R++)
			{
				while(!is_it(c,b[R]))c=p[c];
//				c=lca(c,b[R]);
				if(!is_it(x,c))break;
				if(x==c)
				{
					fin=1;
					cout<<L<<" "<<R<<endl;
				}
			}
		}
		if(!fin)
		{
			cout<<"-1 -1"<<endl;
		}
	}
	
}
 
 
	return 0;
}

Compilation message

treearray.cpp: In function 'void mshobelize(int, int)':
treearray.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[sad].size();i++)
              ~^~~~~~~~~~~~~~
treearray.cpp: In function 'int main()':
treearray.cpp:99:31: error: invalid conversion from 'int*' to 'int' [-fpermissive]
     while(!is_it(c,b[R]))c=p[c];
                            ~~~^