QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#747246 | #9570. Binary Tree | ucup-team1769# | WA | 1ms | 3596kb | C++14 | 1.2kb | 2024-11-14 16:41:13 | 2024-11-14 16:41:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n;
cin >> n;
set<int> st;
for (int i = 1; i <= n; i++)
st.insert(i);
vector<set<int>> g(n + 10, set<int>());
for (int i = 1; i <= n; i++)
{
int l, r;
cin >> l >> r;
if (l)
{
g[i].insert(l);
g[l].insert(i);
st.erase(l);
}
if (r)
{
g[i].insert(r);
g[r].insert(i);
st.erase(r);
}
}
int root = *st.begin();
int u = root, v = *(g[root].begin());
while (1)
{
cout << "? " << u << ' ' << v << '\n';
fflush(stdout);
int t;
cin >> t;
if (t == 2)
swap(u, v);
g[u].erase(v);
g[v].erase(u);
if (g[u].empty())
{
cout << "! " << u << '\n';
fflush(stdout);
break;
}
v = *(g[u].begin());
}
}
signed main()
{
// cin.tie(0)->ios::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3596kb
input:
2 5 0 0 1 5 2 4 0 0 0 0 2 0
output:
? 3 2 ? 2 1 ? 2 5
result:
wrong answer Too many queries (test case 1)