找不出哪个地方可以RE
查看原帖
找不出哪个地方可以RE
643012
Xiao_Xiao_Yu楼主2023/2/24 18:46
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n,u,v,x,y,wide=0,deep=0;
int width[10005];
//struct point{int l,r,val} 
int tree[20005],pos[20005];
int find(int crt,int dis,bool from_root) //crt -> current position
{
	//cout<<"trying "<<tree[crt]<<endl;
	if(tree[crt]==0) return 0;
	else if(tree[crt]==y)
	{
		cout<<dis<<endl;
		return 1;
	}
	else return find(crt*2,dis+1,1)||find(crt*2+1,dis+1,1)||(!from_root&&find(crt/2,dis+2,0));
}
int main()
{
	memset(tree,0,sizeof(tree));
	memset(width,0,sizeof(width));
	tree[1]=1;pos[1]=1;
	cin>>n;
	//BUILDING TREE
	for(int i=1;i<=n-1;++i)
	{
		cin>>u>>v;
		pos[v]=tree[pos[u]*2]?pos[u]*2+1:pos[u]*2;
		tree[pos[v]]=v;
		int depth=log2(pos[v])+1;
		deep=deep>depth?deep:depth;
		wide=wide>++width[depth]?wide:width[depth];
		//printf("added %d to %d,pos of v = %d, depth = %d, width= %d\n",u,v,pos[v],depth,width[depth]);
	}
	cin>>x>>y;
	//OUTPUT DEPTH AND WIDTH
	cout<<deep<<endl<<wide<<endl;
	//FINDING X & Y'S DISTANCE
	find(pos[x],0,0);
	return 0;
}
2023/2/24 18:46
加载中...