QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#659530 | #8056. Travel 2 | ucup-team4992 | TL | 0ms | 0kb | C++14 | 1.5kb | 2024-10-19 20:34:44 | 2024-10-19 20:34:45 |
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