QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748514#9570. Binary TreeacansaidongWA 1ms5692kbC++202.3kb2024-11-14 20:36:272024-11-14 20:36:28

Judging History

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

  • [2024-11-14 20:36:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5692kb
  • [2024-11-14 20:36:27]
  • 提交

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];
int yu,n;

void f()
{
	queue<pair<int,int>>q;
	for(int i=1;i<=n;i++) if(e[i].size()==1) q.push({i,1});
	while(q.size())
	{
		int x=q.front().first,y=q.front().second;q.pop();
//		cerr<<x<<"\n";
		if(vis[x]!=0) continue;
		vis[x]=max(vis[x],y);
		for(auto i:e[x])
		{
			if(vis[i]==0) q.push({i,y+1});
		}
	}
}

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

詳細信息

Test #1:

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

input:

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

output:

3 ? 5 1

result:

wrong answer Token parameter [name=op] equals to "3", doesn't correspond to pattern "[?!]{1,1}" (test case 1)