QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#829840 | #9911. 路南柯 | hhoppitree# | 5.049462 | 30ms | 3856kb | C++14 | 1.3kb | 2024-12-24 14:08:40 | 2024-12-24 14:08:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
vector<int> G[N];
int deg[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;
int cnt = 0;
for (int i = 1; i <= n; ++i) cnt += (G[i].size() == 1);
--cnt;
printf("%d\n", cnt);
for (int i = 1; i <= n; ++i) if (G[i].size() == 1) {
if (!cnt) continue;
--cnt;
vector<int> z, Q;
for (int j = 1; j <= n; ++j) {
deg[j] = G[j].size();
if (deg[j] == 1) Q.push_back(j);
}
sort(Q.begin(), Q.end(), [&](int x, int y) {
return (x ^ i) < (y ^ i);
});
while (!Q.empty()) {
int x = Q.back(); Q.pop_back();
z.push_back(x);
shuffle(G[x].begin(), G[x].end(), rnd);
for (auto v : G[x]) {
if (--deg[v] == 1) Q.push_back(v);
}
}
for (int j = 0; j < n; ++j) printf("%d%c", z[j], " \n"[j + 1 == n]);
}
}
return 0;
}
詳細信息
Subtask #1:
score: 3.7636
Acceptable Answer
Test #1:
score: 3.7636
Acceptable Answer
time: 0ms
memory: 3856kb
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:
3 10 2 9 7 3 4 6 8 1 5 9 10 2 5 1 8 6 4 3 7 7 3 5 10 2 4 6 8 1 9 5 10 7 9 8 2 6 4 5 3 1 10 7 9 8 2 1 6 5 3 4 10 7 9 8 2 1 6 4 3 5 9 10 7 8 2 1 5 4 3 6 6 4 5 1 3 2 10 7 8 9 4 9 6 3 7 2 5 4 8 10 1 9 1 6 3 10 8 7 2 4 5 9 1 5 7 2 4 8 10 3 6 9 1 5 6 3 10 8 4 2 7 4 10 8 7 1 5 3 9 6 2 4 10 8 7 1 4 2 6 9 3 ...
result:
points 0.18818 Partial correct.
Subtask #2:
score: 1.28586
Acceptable Answer
Test #2:
score: 1.28586
Acceptable Answer
time: 30ms
memory: 3736kb
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:
37 94 28 25 77 92 91 86 85 82 57 83 80 87 15 81 21 78 79 76 88 71 68 66 67 65 62 63 97 60 58 51 38 95 49 47 45 98 42 40 37 84 41 34 31 52 2 48 54 16 35 93 24 20 26 64 39 6 43 100 59 18 17 36 14 10 4 75 53 5 22 44 8 70 9 61 19 90 7 27 72 89 73 69 23 3 29 33 50 30 46 55 99 11 32 74 96 56 12 13 1 91 92...
result:
points 0.0160732697 Partial correct.