QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747216#9570. Binary Treeucup-team1769#WA 1ms3600kbC++141.4kb2024-11-14 16:36:052024-11-14 16:36:05

Judging History

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

  • [2024-11-14 16:36:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2024-11-14 16:36:05]
  • 提交

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);
        }
    }

    if (st.empty())
    {
        cout << "! 1" << '\n';
        cout.flush();
        return;
    }
    int root = *st.begin();

    if (g[root].empty())
    {
        cout << "! 1" << '\n';
        cout.flush();
        return;
    }
    int u = root, v = *(g[root].begin());
    while (1)
    {
        cout << "? " << u << ' ' << v << '\n';
        cout.flush();

        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';
            cout.flush();
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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)