QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734092#9570. Binary Treexly_tyty#Compile Error//C++231.9kb2024-11-10 23:59:402024-11-10 23:59:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 23:59:41]
  • 评测
  • [2024-11-10 23:59:40]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int T,n,root,size[100010],maxs[100010];
vector<int> e[100010];
bool mark[100010];
void find(int now,int fa,int Size)
{
	size[now]=1,maxs[now]=0;
	for(int i=0;i<e[now].size();i++)
	{
		int t=e[now][i];
		if(t==fa||mark[t])
		{
			continue;
		}
		find(t,now,Size);
		size[now]+=size[t];
		maxs[now]=max(maxs[now],size[t]);
	}
	maxs[now]=max(maxs[now],Size-size[now]);
	if(!root||maxs[now]<maxs[root])
	{
		root=now;
	}
}
inline bool cmp(int x,int y)
{
	return size[x]<size[y];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			e[i].clear();
			mark[i]=0;
		}
		for(int i=1,x,y;i<=n;i++)
		{
			cin>>x>>y;
			if(x)
			{
				e[i].emplace_back(x);
				e[x].emplace_back(i);
			}
			if(y)
			{
				e[i].emplace_back(y);
				e[y].emplace_back(i);
			}
		}
		int now=1;
		size[1]=n;
		while(1)
		{
			root=0,find(now,now,size[now]);
			int r=root;
			find(r,r,0),root=r;
			vector<int> v;
			for(int i=0;i<e[root].size();i++)
			{
				int t=e[root][i];
				if(mark[t])
				{
					continue;
				}
				v.emplace_back(t);
			}
			sort(v.begin(),v.end(),cmp);
			if(v.empty())
			{
				cout<<"! "<<root<<endl;
				break;
			}
			if(v.size()==1)
			{
				cout<<"? "<<root<<" "<<v.back()<<endl;
				int x;
				cin>>x;
				cout<<"! "<<(x?v.back():root)<<endl;
				break;
			}
			if(v.size()==2)
			{
				cout<<"? "<<v[0]<<" "<<v[1]<<endl;
				int x;
				cin>>x;
				if(x==1)
				{
					cout<<"! "<<root<<endl;
					break;
				}
				mark[root]=1;
				now=x?v[1]:v[0];
			}
			if(v.size()==3)
			{
				cout<<"? "<<v[1]<<" "<<v[2]<<endl;
				int x;
				cin>>x;
				if(x==1)
				{
					mark[v[1]]=mark[v[2]]=1;
					size[now=root]=size[v[0]]+1;
					continue;
				}
				mark[root]=1;
				now=x?v[2]:v[1];
			}
		}
	}
	return 0;
}

詳細信息

answer.code: In function ‘void find(int, int, int)’:
answer.code:10:9: error: reference to ‘size’ is ambiguous
   10 |         size[now]=1,maxs[now]=0;
      |         ^~~~
In file included from /usr/include/c++/13/string:53,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from answer.code:1:
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:5:14: note:                 ‘int size [100010]’
    5 | int T,n,root,size[100010],maxs[100010];
      |              ^~~~
answer.code:19:17: error: reference to ‘size’ is ambiguous
   19 |                 size[now]+=size[t];
      |                 ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:5:14: note:                 ‘int size [100010]’
    5 | int T,n,root,size[100010],maxs[100010];
      |              ^~~~
answer.code:19:28: error: reference to ‘size’ is ambiguous
   19 |                 size[now]+=size[t];
      |                            ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:5:14: note:                 ‘int size [100010]’
    5 | int T,n,root,size[100010],maxs[100010];
      |              ^~~~
answer.code:20:41: error: reference to ‘size’ is ambiguous
   20 |                 maxs[now]=max(maxs[now],size[t]);
      |                                         ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:5:14: note:                 ‘int size [100010]’
    5 | int T,n,root,size[100010],maxs[100010];
      |              ^~~~
answer.code:22:38: error: reference to ‘size’ is ambiguous
   22 |         maxs[now]=max(maxs[now],Size-size[now]);
      |                                      ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:5:14: note:                 ‘int size [100010]’
    5 | int T,n,root,size[100010],maxs[100010];
      |              ^~~~
answer.code: In function ‘bool cmp(int, int)’:
answer.code:30:16: error: reference to ‘size’ is ambiguous
   30 |         return size[x]<size[y];
      |                ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’
  274 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/13/bits/range_access.h:264:5: note:                 ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’
  264 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
answer.code:5:14: note:                 ‘int size [100010]’
    5 | int T,n,root,si...