QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582292 | #8239. Mysterious Tree | argtarg | TL | 0ms | 0kb | C++20 | 1.2kb | 2024-09-22 15:57:40 | 2024-09-22 15:57:41 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pii pair<int, int>
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T = 1;
cin >> T;
while (T--)solve();
return 0;
}
const int mod = 998244353;
void solve() {
int n;
cin >> n;
auto co = [&](int x, int y)->void {
cout << "? " << x << ' ' << y << endl;
};
for (int i = 1; i <= n; i+=2) {
int x = i, y = i + 1;
if (x == n)y = 1;
co(x, y);
int t;
cin >> t;
if (t == 1) {
int num = 0;
int nx = 0;
for (int j = 1; j <= n; j++) {
if (j == x || j == y)continue;
if (num == 0) {
co(x, j);
num++;
int a;
cin >> a;
co(y, j);
int b;
cin >> b;
if (a == 1) {
nx = x;
}
else if(b==1){
nx = y;
}
else {
cout << "! " << 1 << endl;
return;
}
}
else {
co(nx, j);
int t;
cin >> t;
if (t == 1) {
cout << "! 2\n";
}
else {
cout << "! 1\n";
}
return;
}
}
return;
}
}
cout << "! 1\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 4