QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734756#9570. Binary TreeTom22lCompile Error//C++232.1kb2024-11-11 14:55:492024-11-11 14:55:49

Judging History

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

  • [2024-11-11 14:55:49]
  • 评测
  • [2024-11-11 14:55:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int Read(){
	int x=0;
	char ch=getchar();bool f=0;
	while(ch<'0'||ch>'9') if(ch=='-')f=1,ch=getchar(); else if(ch==EOF)return 0; else ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
int fa[100005],l[100005],r[100005];
int root;
int size[100005];
int n;
bool flag;
void dfs(int x){
	size[x]=1;
	if(l[x]){dfs(l[x]);size[x]+=size[l[x]];}
	if(r[x]){dfs(r[x]);size[x]+=size[r[x]];}
	if(flag) return;
	if(size[l[x]]<=n/2&&size[r[x]]<=n/2&&n-size[x]+1<=n/2&&l[x]&&r[x]){
		flag=1;
		printf("? %d %d\n",l[x],r[x]);
		fflush(stdout);
		int op=Read();
		if(op==1)l[x]=0,r[x]=0,n=n-size[x]+1;
		if(op==2)root=r[x],n=size[r[x]],fa[r[x]]=0;
		if(op==0)root=l[x],n=size[l[x]],fa[l[x]]=0;
		return;
	}if(size[l[x]]<=n/2&&size[r[x]]+1<=n/2&&n-size[x]<=n/2&&fa[x]&&l[x]){
		flag=1;
		printf("? %d %d\n",l[x],fa[x]);
		fflush(stdout);
		int op=Read();
		if(op==1)l[x]=0,fa[x]=0,root=x,n=size[r[x]]+1;
		if(op==2){
			n=n-size[x];
			if(l[fa[x]]==x) l[fa[x]]=0;
			if(r[fa[x]]==x) r[fa[x]]=0;
		}
		if(op==0)root=l[x],n=size[l[x]],fa[l[x]]=0;
		return;
	}if(size[l[x]]+1<=n/2&&size[r[x]]<=n/2&&n-size[x]<=n/2&&fa[x]&&r[x]){
		flag=1;
		printf("? %d %d\n",r[x],fa[x]);
		fflush(stdout);
		int op=Read();
		if(op==1)r[x]=0,fa[x]=0,root=x,n=size[l[x]]+1;
		if(op==2){
			n=n-size[x];
			if(l[fa[x]]==x) l[fa[x]]=0;
			if(r[fa[x]]==x) r[fa[x]]=0;
		}
		if(op==0)root=r[x],n=size[r[x]],fa[r[x]]=0;
		return;
	}
	return;
}
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int T=Read();
	while(T--){
		n=Read();
		for(int i=1;i<=n;i++) fa[i]=0;
		for(int i=1;i<=n;i++){
			l[i]=Read(),r[i]=Read();
			if(l[i])fa[l[i]]=i;
			if(r[i])fa[r[i]]=i;
		}
		for(int i=1;i<=n;i++) if(!fa[i]) root=i;
		while(n>2){
			flag=0;
			dfs(root);
		}if(n==1){
			printf("! %d\n",root);
			fflush(stdout);
		}else{
			printf("? %d %d\n",root,l[root]?l[root]:r[root]);
			fflush(stdout);
			int op=Read();
			printf("! %d\n",op==0?root:(l[root]?l[root]:r[root]));
			fflush(stdout);
		}
	}
	return 0; 
}

Details

answer.code: In function ‘void dfs(int)’:
answer.code:16:9: error: reference to ‘size’ is ambiguous
   16 |         size[x]=1;
      |         ^~~~
In file included from /usr/include/c++/13/string:53,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 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:12:5: note:                 ‘int size [100005]’
   12 | int size[100005];
      |     ^~~~
answer.code:17:28: error: reference to ‘size’ is ambiguous
   17 |         if(l[x]){dfs(l[x]);size[x]+=size[l[x]];}
      |                            ^~~~
/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:12:5: note:                 ‘int size [100005]’
   12 | int size[100005];
      |     ^~~~
answer.code:17:37: error: reference to ‘size’ is ambiguous
   17 |         if(l[x]){dfs(l[x]);size[x]+=size[l[x]];}
      |                                     ^~~~
/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:12:5: note:                 ‘int size [100005]’
   12 | int size[100005];
      |     ^~~~
answer.code:18:28: error: reference to ‘size’ is ambiguous
   18 |         if(r[x]){dfs(r[x]);size[x]+=size[r[x]];}
      |                            ^~~~
/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:12:5: note:                 ‘int size [100005]’
   12 | int size[100005];
      |     ^~~~
answer.code:18:37: error: reference to ‘size’ is ambiguous
   18 |         if(r[x]){dfs(r[x]);size[x]+=size[r[x]];}
      |                                     ^~~~
/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:12:5: note:                 ‘int size [100005]’
   12 | int size[100005];
      |     ^~~~
answer.code:20:12: error: reference to ‘size’ is ambiguous
   20 |         if(size[l[x]]<=n/2&&size[r[x]]<=n/2&&n-size[x]+1<=n/2&&l[x]&&r[x]){
      |            ^~~~
/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:12:5: note:                 ‘int size [100005]’
   12 | int size[100005];
      |     ^~~~
answer.code:20:29: error: reference to ‘size’ is ambiguous
   20 |         if(size[l[x]]<=n/2&&size[r[x]]<=n/2&&n-size[x]+1<=n/2&&l[x]&&r[x]){
      |                             ^~~~
/usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm...