#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
std::vector<std::vector<int>> adj(N);
for (int i = 0; i < M; ++i) {
int A, B;
std::cin >> A >> B;
--A, --B;
adj[A].emplace_back(B);
adj[B].emplace_back(A);
}
std::vector<int> dp(1 << N, -1);
std::vector<std::pair<int, int>> save(1 << N);
dp[0] = 0;
auto dfs = [&](auto&& self, int mask) -> int {
if (dp[mask] != -1) {
return dp[mask] == -2 ? 10 * N : dp[mask];
}
dp[mask] = -2;
std::array<int, 3> ans = {10 * N, -1, -1};
for (int i = 0; i < N; ++i) {
int nmask = 0;
for (int j = 0; j < N; ++j) {
if (mask >> j & 1 && i != j) {
for (auto u : adj[j]) {
nmask |= (1 << u);
}
}
}
debug(mask, nmask);
ans = std::min(ans, {self(self, nmask) + 1, i, nmask});
}
save[mask] = {ans[1], ans[2]};
return dp[mask] = ans[0];
};
int ans = dfs(dfs, (1 << N) - 1);
if (ans >= 10 * N) {
std::cout << "NO\n";
} else {
std::cout << "YES\n";
std::cout << ans << '\n';
int mask = (1 << N) - 1;
while (mask != 0) {
std::cout << save[mask].first + 1 << ' ';
mask = save[mask].second;
}
std::cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
508 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
508 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
1 ms |
592 KB |
Output is correct |
33 |
Partially correct |
1 ms |
592 KB |
Provide a successful but not optimal strategy. |
34 |
Correct |
1 ms |
760 KB |
Output is correct |
35 |
Correct |
2 ms |
848 KB |
Output is correct |
36 |
Correct |
1 ms |
848 KB |
Output is correct |
37 |
Correct |
2 ms |
848 KB |
Output is correct |
38 |
Correct |
2 ms |
848 KB |
Output is correct |
39 |
Correct |
1 ms |
1104 KB |
Output is correct |
40 |
Correct |
1 ms |
1188 KB |
Output is correct |
41 |
Correct |
1 ms |
1104 KB |
Output is correct |
42 |
Correct |
1 ms |
1104 KB |
Output is correct |
43 |
Correct |
2 ms |
2004 KB |
Output is correct |
44 |
Correct |
2 ms |
1872 KB |
Output is correct |
45 |
Correct |
2 ms |
1872 KB |
Output is correct |
46 |
Correct |
2 ms |
1872 KB |
Output is correct |
47 |
Correct |
2 ms |
3408 KB |
Output is correct |
48 |
Correct |
3 ms |
3408 KB |
Output is correct |
49 |
Correct |
2 ms |
3408 KB |
Output is correct |
50 |
Correct |
2 ms |
3408 KB |
Output is correct |
51 |
Correct |
2 ms |
6480 KB |
Output is correct |
52 |
Correct |
2 ms |
6480 KB |
Output is correct |
53 |
Correct |
2 ms |
6480 KB |
Output is correct |
54 |
Partially correct |
2 ms |
6492 KB |
Provide a successful but not optimal strategy. |
55 |
Correct |
3 ms |
12624 KB |
Output is correct |
56 |
Correct |
2 ms |
12624 KB |
Output is correct |
57 |
Correct |
3 ms |
12624 KB |
Output is correct |
58 |
Correct |
2 ms |
12624 KB |
Output is correct |
59 |
Correct |
3 ms |
12880 KB |
Output is correct |
60 |
Correct |
3 ms |
12744 KB |
Output is correct |
61 |
Correct |
3 ms |
12624 KB |
Output is correct |
62 |
Correct |
3 ms |
12624 KB |
Output is correct |
63 |
Correct |
2 ms |
12624 KB |
Output is correct |
64 |
Correct |
3 ms |
12624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
11 |
Runtime error |
3 ms |
2128 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
508 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
508 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
1 ms |
592 KB |
Output is correct |
33 |
Partially correct |
1 ms |
592 KB |
Provide a successful but not optimal strategy. |
34 |
Correct |
1 ms |
760 KB |
Output is correct |
35 |
Correct |
2 ms |
848 KB |
Output is correct |
36 |
Correct |
1 ms |
848 KB |
Output is correct |
37 |
Correct |
2 ms |
848 KB |
Output is correct |
38 |
Correct |
2 ms |
848 KB |
Output is correct |
39 |
Correct |
1 ms |
1104 KB |
Output is correct |
40 |
Correct |
1 ms |
1188 KB |
Output is correct |
41 |
Correct |
1 ms |
1104 KB |
Output is correct |
42 |
Correct |
1 ms |
1104 KB |
Output is correct |
43 |
Correct |
2 ms |
2004 KB |
Output is correct |
44 |
Correct |
2 ms |
1872 KB |
Output is correct |
45 |
Correct |
2 ms |
1872 KB |
Output is correct |
46 |
Correct |
2 ms |
1872 KB |
Output is correct |
47 |
Correct |
2 ms |
3408 KB |
Output is correct |
48 |
Correct |
3 ms |
3408 KB |
Output is correct |
49 |
Correct |
2 ms |
3408 KB |
Output is correct |
50 |
Correct |
2 ms |
3408 KB |
Output is correct |
51 |
Correct |
2 ms |
6480 KB |
Output is correct |
52 |
Correct |
2 ms |
6480 KB |
Output is correct |
53 |
Correct |
2 ms |
6480 KB |
Output is correct |
54 |
Partially correct |
2 ms |
6492 KB |
Provide a successful but not optimal strategy. |
55 |
Correct |
3 ms |
12624 KB |
Output is correct |
56 |
Correct |
2 ms |
12624 KB |
Output is correct |
57 |
Correct |
3 ms |
12624 KB |
Output is correct |
58 |
Correct |
2 ms |
12624 KB |
Output is correct |
59 |
Correct |
3 ms |
12880 KB |
Output is correct |
60 |
Correct |
3 ms |
12744 KB |
Output is correct |
61 |
Correct |
3 ms |
12624 KB |
Output is correct |
62 |
Correct |
3 ms |
12624 KB |
Output is correct |
63 |
Correct |
2 ms |
12624 KB |
Output is correct |
64 |
Correct |
3 ms |
12624 KB |
Output is correct |
65 |
Correct |
1 ms |
336 KB |
Output is correct |
66 |
Correct |
1 ms |
336 KB |
Output is correct |
67 |
Correct |
1 ms |
336 KB |
Output is correct |
68 |
Correct |
1 ms |
344 KB |
Output is correct |
69 |
Correct |
1 ms |
336 KB |
Output is correct |
70 |
Correct |
1 ms |
336 KB |
Output is correct |
71 |
Correct |
2 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
336 KB |
Output is correct |
73 |
Correct |
1 ms |
336 KB |
Output is correct |
74 |
Correct |
1 ms |
336 KB |
Output is correct |
75 |
Correct |
1 ms |
336 KB |
Output is correct |
76 |
Correct |
1 ms |
508 KB |
Output is correct |
77 |
Partially correct |
1 ms |
336 KB |
Provide a successful but not optimal strategy. |
78 |
Correct |
1 ms |
508 KB |
Output is correct |
79 |
Runtime error |
221 ms |
524288 KB |
Execution killed with signal 9 |
80 |
Halted |
0 ms |
0 KB |
- |