QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738068#9570. Binary TreeguanghereWA 3ms3636kbC++14946b2024-11-12 17:38:102024-11-12 17:38:15

Judging History

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

  • [2024-11-12 17:38:15]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3636kb
  • [2024-11-12 17:38:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;   const int N = 1e5+10;

int main(){
	int t, n, x, o;   cin >> t;
	static int l[N], r[N];   static bool a[N];
	while(t--){
		cin >> n;
		for(int i = 1; i <= n; i++)
			cin >> l[i] >> r[i], a[l[i]] = a[r[i]] = 1;
		for(int i = 1; i <= n; i++) if(!a[i]) {x = i; break;}
		while(1){
			if(l[x] && r[x]){
				cout << "? " << l[x] << ' ' << r[x] << '\n';
				cout.flush();   cin >> o;
				if(o == 1) break;   else x = (!o ? l[x] : r[x]);
			}
			else if(l[x] && !r[x]){
				cout << "? " << l[x] << ' ' << x << '\n';
				cout.flush();   cin >> o;
				if(o == 2) break;   else x = l[x];
			}
			else if(!l[x] && r[x]){
				cout << "? " << r[x] << ' ' << x << '\n';
				cout.flush();   cin >> o;
				if(o == 2) break;   else x = r[x];
			}
			else break;
		}
		cout << "! " << x << '\n';   cout.flush();
		for(int i = 1; i <= n; i++) l[i] = r[i] = a[i] = 0;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3636kb

input:

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

output:

? 2 4
? 1 5
! 2
? 2 1
! 1

result:

ok OK (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3612kb

input:

5555
8
2 0
8 6
0 0
3 0
0 0
7 0
0 0
5 4
0
0
2

output:

? 2 1
? 8 6
? 5 4
? 3 4

result:

wrong answer Too many queries (test case 1)