QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87027#4218. Hidden Graph_slbWA 2ms3476kbC++173.4kb2023-03-11 16:21:382023-03-11 16:21:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-11 16:21:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3476kb
  • [2023-03-11 16:21:38]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <utility>
using namespace std;

namespace solve
{
    const int maxn = 2010;
    
    int n;
    vector<pair<int, int>> ans;
    vector<int> a[maxn];
    int belong[maxn];

    pair<int, int> ask(set<int> p)
    {
        cout << "? " << p.size() << ' ';
        for (int x : p)
            cout << x << " ";
        cout << endl;
        int x, y;
        cin >> x >> y;
        return {x, y};
    }
    int K;

    vector<int> e[maxn];
    inline void add(int x, int y) { e[x].push_back(y), e[y].push_back(x); }

    void main()
    {
        cin >> n, K = 1;
        a[1].push_back(1);
        for (int i = 2; i <= n; i++)
        {
            for (int j = 1; j <= K; j++)
            {
                set<int> tmp;
                for (int x : a[j])
                    tmp.insert(x);
                tmp.insert(i);
                while (tmp.size() != 1)
                {
                    auto [x, y] = ask(tmp);
                    if (x == -1 && y == -1)
                        break;
                    ans.emplace_back(x, y), add(x, y);
                    tmp.erase(x == i ? y : x);
                }
                a[j].clear();
            }
            K = 0;
            priority_queue<pair<int, int>> q;
            vector<int> deg(n + 1), vis(n + 1);
            for (int j = 1; j <= i; j++)
                q.push({-deg[j], j});
            while (!q.empty())
            {
                auto o = q.top();
                q.pop();
                int x = o.second;
                if (vis[x])
                    continue;
                vis[x] = 1;
                K = max(K, deg[x] + 1);
                for (int v : e[x])
                {
                    deg[v]--;
                    if (!vis[v])
                        q.push({-deg[v], v});
                }
            }
            vector<int> stk;
            for (int j = 1; j <= i; j++)
                stk.push_back(j);
            vector<int> belong(n + 1);
            fill(vis.begin(), vis.end(), 0);
            while (!stk.empty())
            {
                int x = stk.back();
                stk.pop_back();
                vector<int> used(K + 1);
                vis[x] = 1;
                for (int v : e[x])
                    if (vis[v])
                        used[belong[v]] = 1;
                auto get = [&]()
                {
                    for (int i = 1; i <= n; i++)
                        if (!used[i])
                            return i - 1;
                    return -1;
                };
                belong[x] = get(), a[belong[x]].push_back(x);
                for (int v : e[x])
                    if (!vis[v])
                        stk.push_back(v);
            }
            for (int i = 1; i <= n; i++)
                if (a[i].empty())
                {
                    K = i - 1;
                    break;
                }
        }
        cout << "! " << ans.size() << '\n';
        for (auto [x, y] : ans)
            cout << x << " " << y << '\n';
        cout.flush();
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solve::main();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3476kb

input:

3
1 2

output:

? 2 1 2 
! 1
1 2

result:

wrong answer read 1 edges but expected 3 edges