QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#490921 | #8757. 图 | Hunster | WA | 123ms | 16004kb | C++20 | 1.7kb | 2024-07-25 16:44:06 | 2024-07-25 16:44:07 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int N = 100005;
int n, m;
std::unordered_map<int, int> par[N];
std::unordered_map<int, std::vector<int>> graph[N];
int get_par(int i, int x) { return !par[i][x] ? x : par[i][x] = get_par(i, par[i][x]); }
int fa[N], dep[N];
void print(int i, int s, int t) {
for (auto [x, g] : graph[i]) fa[x] = -1;
const std::function<void(int, int)> dfs = [&](int u, int p) {
fa[u] = p;
dep[u] = dep[p] + 1;
for (int v : graph[i][u]) if (fa[v] == -1) dfs(v, u);
};
dfs(t, 0);
printf("%d", dep[s]);
for (int u = s; u; u = fa[u]) printf(" %d", u);
putchar('\n');
}
int main() {
std::cin.sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T--) {
std::cin >> n >> m;
int k = (m + n - 2) / (n - 1);
for (int i = 1; i <= n; i++) {
par[i].clear();
graph[i].clear();
}
for (int i = 1; i <= m; i++) {
int x, y;
std::cin >> x >> y;
int l = 1, r = k + 1;
while (l < r) {
int mid = (l + r) >> 1;
int px = get_par(mid, x), py = get_par(mid, y);
if (px == py) l = mid + 1;
else r = mid;
}
if (r <= k) {
graph[r][x].push_back(y);
graph[r][y].push_back(x);
int px = get_par(r, x), py = get_par(r, y);
par[r][px] = py;
}
}
for (int i = 1; i <= n; i++) if (int j = get_par(k, i); j != i) {
printf("%d %d\n", i, j);
for (int o = 1; o <= k; o++) print(o, i, j);
break;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 71ms
memory: 14748kb
input:
10000 2 20 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 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 3 5 2 4 1 3 4 2 2 1 2 2 1 4 2 3 5 1 4 2 3 5 1 3 2 3 1 3 2 4 1 4 2 3 5 1 1 5 3 1 4 5 2 1 5 2 1 5 2 1 5 4 1 3 2 5 3 2 2 3 2 3 3 1 2 3 3 1 2 3 3 5 2 ...
result:
ok Answer correct. (10000 test cases)
Test #3:
score: 0
Accepted
time: 72ms
memory: 14748kb
input:
10000 10 20 9 4 8 6 2 10 2 9 7 10 4 6 9 4 2 1 4 7 1 5 7 2 4 1 5 9 7 6 8 2 9 4 5 9 9 8 7 3 2 4 10 20 3 8 8 9 8 7 9 2 3 10 9 3 8 1 9 4 8 9 4 7 7 5 5 10 1 3 3 4 3 7 3 8 3 9 1 4 3 6 2 4 10 20 7 6 8 10 3 8 2 8 4 8 4 8 4 6 4 1 1 7 4 6 5 9 5 2 4 7 10 9 6 7 10 5 2 4 4 1 3 2 4 9 10 20 2 1 9 8 7 6 2 10 9 5 4 ...
output:
2 8 5 2 9 4 6 8 2 2 8 4 2 4 9 8 1 4 4 1 8 9 4 3 1 3 4 2 1 4 4 1 2 4 1 3 4 7 1 2 4 1 4 2 6 4 3 9 5 1 2 2 4 2 3 4 10 2 2 10 4 2 7 4 10 2 2 10 3 2 3 10 1 3 3 1 7 3 3 1 10 3 4 1 8 6 3 3 9 2 3 9 2 3 9 3 3 4 9 1 10 2 1 10 3 1 5 10 2 1 10 7 8 3 7 5 8 2 7 8 2 7 8 4 9 7 4 6 10 1 8 5 9 6 4 1 6 10 5 9 2 4 9 6 ...
result:
ok Answer correct. (10000 test cases)
Test #4:
score: 0
Accepted
time: 34ms
memory: 14760kb
input:
2000 50 50 6 10 21 26 12 42 29 2 3 30 3 28 7 44 44 37 11 4 23 12 49 14 34 41 35 48 33 6 27 9 33 1 33 31 43 35 32 31 20 42 27 40 39 29 34 38 21 15 31 17 3 33 17 18 15 44 50 22 20 25 28 44 23 32 3 23 25 30 50 20 17 2 21 41 46 35 26 7 34 45 34 19 21 10 44 4 28 22 36 21 4 49 44 39 4 36 2 15 21 38 50 50 ...
output:
2 15 8 2 17 31 33 3 28 44 15 2 2 15 7 10 6 7 36 24 9 37 10 2 7 10 15 24 9 15 34 5 8 1 10 36 14 24 2 15 24 4 19 17 4 10 31 1 47 24 36 28 22 3 13 21 26 42 14 49 19 2 4 19 20 11 4 20 47 35 11 2 20 11 1 45 11 1 24 3 31 12 41 22 9 30 19 45 2 1 45 1 13 3 1 2 13 2 1 13 18 19 7 18 46 42 36 26 15 19 2 18 19 ...
result:
ok Answer correct. (2000 test cases)
Test #5:
score: 0
Accepted
time: 101ms
memory: 15588kb
input:
200 50 1000 6 33 31 2 17 37 27 22 36 1 35 12 31 3 8 36 22 15 40 45 13 23 23 24 50 46 41 48 49 35 15 30 14 6 7 24 38 27 43 19 30 16 16 31 49 21 47 44 33 9 27 32 48 23 24 33 25 12 23 50 6 27 20 21 48 11 42 23 8 36 3 34 8 14 17 30 27 1 14 40 37 5 23 24 6 24 5 35 38 43 31 48 25 33 4 13 6 37 22 24 31 32 ...
output:
2 9 10 2 31 16 30 15 22 27 6 33 9 12 2 8 36 47 1 27 6 24 23 11 35 9 6 2 44 15 46 36 9 12 2 37 23 3 36 13 7 24 22 25 34 9 4 2 37 49 9 7 2 44 42 37 14 35 9 6 2 44 41 15 32 9 8 2 42 21 10 39 28 14 9 6 2 1 42 10 41 9 7 2 44 5 11 41 22 9 13 2 5 20 1 33 24 35 21 28 32 10 22 9 10 2 16 29 40 8 20 49 7 34 9 ...
result:
ok Answer correct. (200 test cases)
Test #6:
score: -100
Wrong Answer
time: 123ms
memory: 16004kb
input:
20 100 10000 77 84 14 62 84 5 4 67 99 44 54 18 39 53 58 88 32 3 61 19 76 14 28 72 92 34 20 1 14 66 98 25 53 99 55 40 13 70 42 62 32 41 93 14 74 66 92 62 42 12 94 35 26 65 82 85 100 34 79 47 87 59 4 92 46 4 77 63 17 62 32 23 46 76 61 26 89 41 10 18 17 64 55 61 89 42 8 71 75 89 2 81 9 63 42 32 23 34 7...
output:
5 6 14 5 84 77 63 76 14 62 42 89 20 99 48 91 6 7 5 64 41 87 60 67 6 12 5 66 96 91 72 46 98 31 76 94 69 6 12 5 73 39 68 71 72 98 36 63 65 74 6 11 5 47 17 76 20 42 26 78 33 95 6 12 5 18 96 29 27 76 14 57 62 71 91 6 12 5 31 65 86 15 10 13 43 99 88 80 6 9 5 41 77 43 46 1 49 40 6 14 5 29 36 98 30 57 63 2...
result:
FAIL No edge cross. (test case 2)