QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#659530#8056. Travel 2ucup-team4992TL 0ms0kbC++141.5kb2024-10-19 20:34:442024-10-19 20:34:45

Judging History

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

  • [2024-10-19 20:34:45]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-19 20:34:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2510, M = 10010;
void solve() {
    vector<vector<int>> G(N), stk(N);
    int id, d;
    cin >> id >> d;
    int n = id;
    G[id].resize(d + 1);
    vector<int> sure(N);
    int sure_cnt = 0;
    auto work = [&]() {
        n = max(n, id);
        G[id].resize(d + 1);
        for (int i = 1; i <= d; i++) {
            int& v = G[id][i];
            if (v) continue;
            cout << "! " << i << '\n';
            cout.flush();
            cin >> v >> d;
            stk[v].push_back(id);
            id = v;
            return;
        }
        if (!sure[id]) {
            sure[id]++;
            sure_cnt++;
        }
        for (int i = 1; i <= d; i++) {
            int& v = G[id][i];
            if (v == stk[id].back()) {
                stk[id].pop_back();
                cout << "! " << i << '\n';
                cout.flush();
                cin >> v >> d;
                id = v;
                return;
            }
        }
    };
    while (sure_cnt < n) {
        work();
    }
    cout << "! ";
    for (int i = 1; i <= n; i++) {
        for (int j = G[i].size() - 1; j >= 1; j--) {
            int& v = G[i][j];
            if (i < v) cout << i << ' ' << v << ' ';
        }
    }
    cout << '\n';
    cout.flush();
    string cr;
    cin >> cr;
}
int main() {
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
1 1

output:

! 1

result: