QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#773745#8056. Travel 2yangjlRE 0ms0kbC++203.7kb2024-11-23 10:13:172024-11-23 10:13:18

Judging History

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

  • [2024-11-23 10:13:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-23 10:13:17]
  • 提交

answer

/**
 *    author:  yangjl
 *    created: 2024.11.21 21:33:55
**/
#include <bits/stdc++.h>
#ifdef YJL
#include "debug.h"
#else
#define debug(...)0
#endif
using namespace std;
using ll = long long;

template<class T>
istream& operator>>(istream& is, vector<T>& v) {
    for(auto& x : v) {
        is >> x;
    }
    return is;
}

int qn;
pair<int, int> query(int i) {
    ++qn;
    ++i;
    cout << "> " << i << endl;
    int u, d;
    cin >> u >> d;
    --u;
    return {u,d};
}

void answer(vector<int>const& edges) {
    cout << "! ";
    for(int x : edges) {
        cout << " " << x + 1;
    }
    cout << endl;
    string response;
    cin >> response;
    assert(response == "Correct");
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    // #ifdef YJL
    //     freopen("oo.in", "r", stdin);
    //     freopen("oo.out", "w", stdout);
    // #endif
    int tt;
    cin >> tt;
    while(tt--) {
        qn = 0;
        int u, d;
        cin >> u >> d;
        --u;

        vector<vector<int>> g;
        vector<int> id;
        vector<int> fa;
        auto extend = [&](int u, int d) {
            if(u >= g.size()) {
                g.resize(u + 1);
                id.resize(u + 1);
                fa.resize(u + 1, -1);
            }

            if(g[u].empty()) {
                g[u].resize(d, -1);
            } else {
                assert(d == g[u].size());
            }
        };
        extend(u, d);
        int root = u;

        while(true) {
            while(id[u] < g[u].size() and g[u][id[u]] != -1) {
                id[u]++;
            }
            if(id[u] == g[u].size()) {
                auto it = find(g[u].begin(), g[u].end(), fa[u]);
                if(it == g[u].end()) {
                    assert(fa[u] == -1);
                    break;
                }

                int i = it - g[u].begin();
                auto [v, _] = query(i);
                assert(v == fa[u]);
                u = v;
                continue;
            }

            auto [v, d] = query(id[u]);
            extend(v, d);

            g[u][id[u]] = v;
            id[u]++;
            if(v != root and fa[v] == -1) {
                fa[v] = u;
            }
            u = v;
        }

        debug(g);
        vector<int> es;
        for(int i = 0; i < g.size(); ++i) {
            for(int j : g[i]) {
                assert(j != -1);
                if(i < j) {
                    es.push_back(i);
                    es.push_back(j);
                }
            }
        }
        assert(qn <= g.size() * 2 + es.size());
        answer(es);
    }
    return 0;
}
/*

function<void(int, int)> dfs = [&](int u, int pre) {
            debug(u, pre);
            debug(g);
            while(true) {
                while(id[u] < g[u].size() and g[u][id[u]] != -1) {
                    id[u]++;
                }
                if(id[u] == g[u].size()) {
                    auto it = find(g[u].begin(), g[u].end(), pre);
                    if(it == g[u].end()) {
                        if(pre != -1) {
                            debug(u, pre, g[u]);
                        }
                        assert(pre == -1);
                        return;
                    }
                    int i = it - g[u].begin();
                    // debug(u, pre, g, id);
                    assert(query(i).first == pre);
                    return;
                }

                auto [v, d] = query(id[u]);
                extend(v, d);
                g[u][id[u]] = v;
                id[u]++;
                dfs(v, u);
            }

        };
        dfs(u, -1);
*/

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
Correct
1 3
2 2
1 3
3 1
1 3
4 2
1 3

output:

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

result: