QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#680610#8056. Travel 2MCdycRE 0ms0kbC++232.2kb2024-10-26 21:46:232024-10-26 21:46:23

Judging History

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

  • [2024-10-26 21:46:23]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-26 21:46:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int solve()
{
    vector<vector<int>> g;
    vector<bool> vis;
    vector<set<int>> q;
    vector<int> fa;
    vector<map<int, int>> pos;
    set<pair<int, int>> ans;
    auto resize = [&](int x) {
        if (vis.size() <= x)
        {
            g.resize(x + 1);
            vis.resize(x + 1);
            q.resize(x + 1);
            fa.resize(x + 1);
            pos.resize(x + 1);
        }
    };
    auto add = [&](int x, int y) {
        if (x > y)
            swap(x, y);
        ans.emplace(x, y);
    };
    int sum = 0;
    int father, size;
    cin >> father >> size;
    resize(father);
    sum += size;
    vis[father] = 1;
    int cnt = 0;
    g[father].resize(size + 1);
    for (int i = 1; i <= size; i++)
    {
        q[father].emplace(i);
    }

    while (cnt < sum)
    {
        int x, l;
        if (q[father].empty())
        {
            cout << "> " << pos[father][fa[father]] << endl;
            cin >> x >> l;
        }
        else
        {
            int t = *q[father].begin();
            cout << "> " << t << endl;
            cin >> x >> l;
            g[father][t] = x;
            pos[father][x] = t;
            q[father].erase(q[father].begin());
            add(father, x);
            cnt++;
            if (!vis[x])
            {
                resize(x);
                sum += l;
                fa[x] = father;
                g[x].resize(l + 1);
                for (int i = 1; i <= l; i++)
                {
                    q[x].emplace(i);
                }
            }
            else
            {
                if (x == fa[father])
                {
                    cout << "> " << pos[x][father] << endl;
                    cin >> x >> l;
                }
            }
        }
        father = x;
        vis[x] = 1;
    }
    cout << "!";
    for (auto it : ans)
        cout << " " << it.first << " " << it.second;
    cout << endl;
    string trash;
    cin >> trash;
    return 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int test = 1;
    cin >> test;
    while (test--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
1 1
2 1
1 1
2 1
Correct
1 3
2 2
1 3
2 2
4 2

output:

> 1
> 1
> 1
! 1 2
> 1
> 1
> 1
> 2

result: