QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#735884#9570. Binary Treepaoxiaomo#WA 0ms7876kbC++203.1kb2024-11-11 22:19:112024-11-11 22:19:11

Judging History

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

  • [2024-11-11 22:19:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7876kb
  • [2024-11-11 22:19:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b))
#define pb push_back
#define LNF 1e18
#define INF 0x7fffffff
#define int long long
#define lowbit(x) ((x) & (-x))
#define abs(x) llabs(x)
// #define endl '\n'
#define Y() cout << "Yes" << endl
#define N() cout << "No" << endl
const db eps = 1e-9;
const int mod = 998244353;
const int MAXN = 2e5 + 5;
vector<pair<int, int>> pth[500005];
int siz[500005], maxp[500005], vis[500005], root, ans = 0, n;

void get_root(int pos, int fa, int total)
{
    siz[pos] = 1;
    maxp[pos] = 0;
    for (auto &[to, w] : pth[pos])
    {
        if (to == fa || vis[to])
            continue;
        get_root(to, pos, total);
        siz[pos] += siz[to];
        maxp[pos] = max(maxp[pos], siz[to]);
    }
    maxp[pos] = max(maxp[pos], total - siz[pos]);
    if (!root || maxp[pos] < maxp[root])
        root = pos;
}

int calc(int pos)
{
    int good = 0;
    vector<int> nu;
    for (auto &[to, w] : pth[pos])
    {
        if (!vis[to])
        {
            good++;
            nu.push_back(to);
        }
    }

    if (good == 0)
    {
        cout << "! " << pos << endl;
        return -1;
    }
    else if (good == 1)
    {
        cout << "? " << nu[0] << " " << pos << endl;
        int t;
        cin >> t;
        if (t == 0)
            cout << nu[0] << endl;
        else
            cout << "! " << pos << endl;
        return -1;
    }
    else if (good == 2)
    {
        cout << "? " << nu[0] << " " << nu[1] << endl;
        int t;
        cin >> t;
        if (t == 1)
        {
            cout << "! " << pos << endl;
            return -1;
        }
        else if (t == 0)
        {
            return nu[0];
        }
        else
            return nu[1];
    }
    else
    {
        cout << "? " << nu[0] << " " << nu[1] << endl;
        int t;
        cin >> t;
        if (t == 1)
        {
            return nu[2];
        }
        else if (t == 0)
        {
            return nu[0];
        }
        else
            return nu[1];
    }
}
void sol(int pos)
{

    vis[pos] = 1;
    int nu = calc(pos);
    if (nu == -1)
        return;
    for (auto &[to, w] : pth[pos])
    {
        if (to == nu)
        {
            maxp[root = 0] = n;
            get_root(to, 0, siz[to]);
            sol(root);
        }
    }
}

void add(int a, int b)
{
    pth[a].push_back({b, 1});
    pth[b].push_back({a, 1});
}
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int a, b;
        cin >> a >> b;
        if (a)
            add(a, i);
        if (b)
            add(b, i);
    }
    maxp[root = 0] = n;
    get_root(1, 0, n);
    sol(root);
    for (int i = 1; i <= n; i++)
        pth[i].clear();
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
     cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 7876kb

input:

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

output:

? 1 5
? 3 4
3

result:

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