QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418486 | #4513. Slide Parade | Whicy | 0 | 2497ms | 34780kb | C++20 | 2.3kb | 2024-05-23 14:12:39 | 2024-05-23 14:12:39 |
Judging History
answer
#include <iostream>
#include <vector>
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T;
std::cin >> T;
for (int TC = 1; TC <= T; TC++) {
std::cout << "Case #" << TC << ": ";
int n, m;
std::cin >> n >> m;
std::vector<std::vector<int>> ed(n), rved(n);
for (int i = 0; i < m; i++) {
int u, v;
std::cin >> u >> v;
ed[--u].push_back(--v);
rved[v].push_back(u);
}
bool imp = 0;
std::vector<int> lnk(n, -1), vis(n, 0);
auto dfs = [&](const auto &dfs, const int &u, std::vector<bool> &vis) -> bool {
for (int v : ed[u]) {
if (vis[v])
continue;
vis[v] = 1;
if (!~lnk[v] || dfs(dfs, lnk[v], vis)) {
lnk[v] = u;
return true;
}
}
return false;
};
int cnt = 0;
for (int i = 0; i < n; i++) {
std::vector<bool> vis(n, 0);
if (dfs(dfs, i, vis))
cnt++;
}
if (cnt < n) {
std::cout << "IMPOSSIBLE\n";
continue;
}
std::vector<std::vector<int>> nwed(n);
for (int u = 0; u < n; u++) {
if (imp)
break;
for (auto v : ed[u]) {
if (lnk[v] == u) {
for (int i = 0; i < n; i++) {
nwed[lnk[i]].push_back(i);
}
continue;
}
for (int i = 0; i < n; i++)
if (lnk[i] == u)
lnk[i] = -1;
int tmp = lnk[v];
lnk[v] = u;
std::vector<bool> vis(n, 0);
vis[v] = 1;
if (!dfs(dfs, tmp, vis)) {
imp = 1;
break;
}
for (int i = 0; i < n; i++) {
nwed[lnk[i]].push_back(i);
}
}
}
if (imp) {
std::cout << "IMPOSSIBLE\n";
continue;
}
std::cout << n * m + 1 << "\n";
std::vector<int> ans(n * m);
int cans = 0;
auto fnd = [&](const auto &fnd, const int &u) -> void {
while (nwed[u].size()) {
int v = nwed[u].back();
nwed[u].pop_back();
fnd(fnd, v);
ans[cans++] = u;
}
};
fnd(fnd, 0);
int st = 0;
for (; ans[st] != 0; st++)
;
for (int i = st; ~i; i--) {
std::cout << ans[i] + 1 << " ";
}
for (int i = n * m - 1; i > st; i--) {
std::cout << ans[i] + 1 << " ";
}
std::cout << "1\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3540kb
input:
100 5 8 1 2 1 3 1 4 1 5 2 1 3 1 4 1 5 1 5 10 1 3 1 4 2 3 2 5 3 1 3 4 3 5 4 2 5 1 5 3 5 10 1 4 2 3 2 5 3 1 3 5 4 2 4 3 4 5 5 1 5 2 3 6 1 2 1 3 2 1 2 3 3 1 3 2 5 10 1 2 1 5 2 3 2 4 3 1 4 3 4 5 5 2 5 3 5 4 4 10 1 2 1 3 1 4 2 1 2 3 2 4 3 1 3 4 4 2 4 3 5 10 1 2 1 3 2 1 2 4 3 1 3 5 4 2 4 5 5 3 5 4 5 10 1 ...
output:
Case #1: IMPOSSIBLE Case #2: 51 1 3 4 2 5 1 4 2 5 3 1 4 2 3 5 1 4 2 3 5 1 4 2 3 5 1 3 4 2 5 1 4 2 5 3 1 4 2 5 3 1 4 2 3 5 1 4 2 5 3 1 Case #3: 51 1 4 2 3 5 1 4 3 1 4 2 5 2 3 5 1 4 5 2 3 1 4 3 1 4 2 5 2 3 5 1 4 2 3 5 1 4 3 1 4 3 1 4 2 5 2 5 2 3 5 1 Case #4: 19 1 2 3 1 3 2 1 2 3 1 2 3 1 3 2 1 3 2 1 Ca...
result:
wrong answer invalid move (from 1 to 1) (test case 25)
Test #2:
score: 0
Wrong Answer
time: 2497ms
memory: 34780kb
input:
100 199 4980 1 95 1 96 1 105 1 124 1 130 1 131 1 135 1 137 1 139 1 140 1 141 1 147 1 155 1 172 1 174 1 179 1 183 1 188 1 193 1 196 1 197 2 3 2 5 2 13 2 14 2 17 2 20 2 24 2 26 2 30 2 41 2 44 2 45 2 52 2 56 2 67 2 70 2 71 2 74 2 78 2 84 2 85 2 90 2 92 2 93 2 97 2 107 2 111 2 113 2 122 2 124 2 128 2 13...
output:
Case #1: IMPOSSIBLE Case #2: IMPOSSIBLE Case #3: 1000001 1 18 192 32 161 115 167 51 24 73 45 33 173 14 135 139 158 175 113 117 19 20 108 6 177 186 31 85 126 146 3 95 154 44 144 156 174 6 177 186 31 85 126 146 11 137 65 193 83 58 130 60 84 93 107 77 47 21 131 145 34 194 40 55 179 151 9 188 5 87 5 87 ...
result:
wrong answer invalid move (from 1 to 1) (test case 27)