QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748083#9570. Binary TreeacansaidongWA 1ms5792kbC++201.3kb2024-11-14 19:16:462024-11-14 19:16:47

Judging History

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

  • [2024-11-14 19:16:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5792kb
  • [2024-11-14 19:16:46]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
 
const int N=2e5+10;
const int M=0x3f3f3f3f3f3f3f3f;
vector<int>e[N];
int a[N],b[N],vis[N];


signed main()
{
	// ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--)
	{
		int n;cin>>n;int ans=1;
        for(int i=1;i<=n;i++) vis[i]=0,e[i].clear();
        for(int i=1;i<=n;i++)
        {
            int x,y;cin>>x>>y;
            a[i]=x;b[i]=y;
            vis[x]++;vis[y]++;
            if(y) e[i].push_back(y);
            if(x) e[i].push_back(x);
        }
		int yu=1,u,v,t,la=0;
        for(int i=1;i<=n;i++) if(vis[i]==0) {yu=i;break;}
        u=yu;v=e[u][0];
        int yui=floor(log2(n));
        while(yui--)
        {
            cout<<"? "<<u<<" "<<v<<endl;
            cin>>t;
            if(t==0)
            {
                if(e[u].size()==1) {ans=u;break;}
                else if(u==la) {ans=u;break;}
                else 
                {
                    la=u;v=e[u][1];
                }
            }
            else if(t==2)
            {
                la=v;u=v;
                if(a[v]==0&&b[v]==0)
                {
					ans=v;break;
				}
				else
				{
					v=e[u][0];
				}
            }
        }
        cout<<"! "<<ans<<"\n";
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5792kb

input:

2
5
0 0
1 5
2 4
0 0
0 0
0
2

output:

? 3 4
? 3 2
! 1

result:

wrong answer There are 3 candidates. (test case 1)