QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#877259#8056. Travel 2FangYifanTL 0ms0kbC++201.3kb2025-01-31 20:39:512025-01-31 20:39:53

Judging History

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

  • [2025-01-31 20:39:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2025-01-31 20:39:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
constexpr int mod = 998244353;

constexpr int N = 2510;
vector<int> edge[N];
int n, deg[N], cur[N], vis[N];
int move(int id) {
    cout << "> " << id << endl;
    int x; cin >> x >> deg[x];
    return x;
}
void dfs(int u, int fa) {
    if (!vis[u]) n++;
    vis[u] = true;
    bool flag = false;
    for (int &i = cur[u]; i < deg[u];) {
        int v = move(++i);
        edge[u].push_back(v);
        if (v == fa) {
            flag = true;
            break;
        }
        dfs(v, u);
    }
    if (!flag) {
        for (int j = 0; j < (int)edge[u].size(); j++) {
            if (edge[u][j] == fa) move(j + 1);
        }
    }
}
void solve() {
    int root; cin >> root >> deg[1];
    dfs(1, 0);
    cout << "!";
    for (int i = 1; i <= n; i++) {
        for (auto j : edge[i]) {
            if (i < j) cout << ' ' << i << ' ' << j;
        }
    }
    cout << endl;
    string Correct; cin >> Correct;
    for (int i = 1; i <= n; i++) {
        deg[i] = cur[i] = vis[i] = 0;
        edge[i].clear();
    }
    n = 0;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

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

result: