QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#830224 | #9911. 路南柯 | hhoppitree# | 61.748738 | 28ms | 3804kb | C++14 | 1.2kb | 2024-12-24 17:08:59 | 2024-12-24 17:09:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
vector<int> G[N];
int deg[N], vis[N];
signed main() {
int T; scanf("%d", &T);
while (T--) {
int n; scanf("%d", &n);
for (int i = 1; i <= n; ++i) G[i].clear();
for (int i = 1, x, y; i < n; ++i) {
scanf("%d%d", &x, &y), G[x].push_back(y), G[y].push_back(x);
}
mt19937 rnd;
vector<int> z;
for (int i = 1; i <= n; ++i) {
if (G[i].size() == 1) z.push_back(i);
}
if (T >= 998) z.pop_back();
printf("%d\n", (int)z.size());
for (auto x : z) {
vector<int> val;
memset(vis, 0, sizeof(vis));
vis[x] = 1;
queue<int> Q;
Q.push(x);
while (!Q.empty()) {
int v = Q.front(); Q.pop();
val.push_back(v);
shuffle(G[v].begin(), G[v].end(), rnd);
for (auto w : G[v]) if (!vis[w]++) Q.push(w);
}
reverse(val.begin(), val.end());
for (int i = 0; i < n; ++i) printf("%d%c", val[i], " \n"[i + 1 == n]);
}
}
return 0;
}
详细
Subtask #1:
score: 18.7173
Acceptable Answer
Test #1:
score: 18.7173
Acceptable Answer
time: 1ms
memory: 3728kb
input:
10 10 4 2 5 1 8 6 1 9 3 7 1 8 10 2 6 4 3 4 10 4 3 3 1 5 3 6 3 2 3 8 7 8 2 7 10 8 9 10 5 4 10 8 10 3 6 3 9 8 1 10 4 2 2 7 8 4 10 10 6 6 8 1 7 2 6 3 5 3 9 4 2 6 9 3 1 10 2 8 10 4 9 1 9 3 5 7 6 3 1 8 8 7 4 2 10 9 2 9 1 7 1 5 6 8 2 3 9 5 10 5 4 1 10 10 2 9 8 1 8 5 6 3 7 1 6 2 9 8 2 10 4 2 10 5 7 6 2 8 7...
output:
4 7 10 3 2 4 6 9 8 1 5 5 9 1 10 8 2 6 4 3 7 10 7 2 3 4 6 5 8 1 9 9 5 1 7 8 3 6 4 2 10 6 10 9 7 8 4 2 5 6 3 1 10 7 9 8 1 2 5 6 3 4 10 9 7 8 2 1 6 4 3 5 10 9 7 8 2 5 1 4 3 6 5 1 6 4 10 3 7 2 8 9 4 1 6 5 3 9 2 8 7 10 5 7 2 5 6 9 4 3 8 10 1 6 1 3 9 10 7 8 2 4 5 7 5 2 4 9 1 8 10 3 6 6 3 1 10 9 5 8 4 2 7 ...
result:
points 0.935865781 Partial correct.
Subtask #2:
score: 43.0314
Acceptable Answer
Test #2:
score: 43.0314
Acceptable Answer
time: 28ms
memory: 3804kb
input:
100 100 90 19 79 98 23 34 50 41 31 52 61 19 50 30 49 5 95 65 22 44 72 89 49 77 27 7 48 2 28 25 56 12 97 63 98 43 10 4 50 33 12 13 54 16 100 43 23 69 53 5 56 85 39 6 64 92 100 59 2 71 44 29 59 97 64 39 75 53 59 89 16 35 67 16 6 43 38 51 36 22 58 70 3 29 9 61 99 11 49 95 27 72 73 89 23 3 14 3 61 57 26...
output:
38 31 71 52 76 91 2 40 88 48 20 37 67 54 78 26 92 84 16 66 64 35 47 39 24 93 45 79 82 6 98 9 57 7 43 62 63 94 61 27 100 97 10 28 51 19 72 59 4 25 38 65 42 90 89 80 75 77 95 73 87 53 49 17 81 60 69 15 34 5 36 21 14 23 68 22 3 44 29 41 33 50 83 58 8 30 70 86 46 55 18 99 11 32 74 96 85 56 12 13 1 1 13 ...
result:
points 0.5378927802 Partial correct.