#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>> gr(1 << N);
for (int i = 0; i < M; ++i) {
int A, B;
std::cin >> A >> B;
--A, --B;
gr[A].emplace_back(B);
gr[B].emplace_back(A);
}
std::vector<std::vector<std::pair<int, int>>> adj(1 << N);
std::vector<int> dp(1 << N, -1), vis(1 << N);
std::vector<std::pair<int, int>> save(1 << N);
dp[0] = 0;
auto dfs = [&](auto&& self, int mask) -> void {
if (vis[mask]) {
return;
}
vis[mask] = true;
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 : gr[j]) {
nmask |= (1 << u);
}
}
}
debug(mask, nmask);
adj[nmask].emplace_back(mask, i);
self(self, nmask);
}
};
dfs(dfs, (1 << N) - 1);
std::vector<int> dep((1 << N), -1);
std::vector<std::pair<int, int>> bef((1 << N));
std::queue<int> que;
que.emplace(0);
dep[0] = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
for (auto[u, i] : adj[v]) {
if (dep[u] == -1) {
dep[u] = dep[v] + 1;
bef[u] = {v, i};
que.emplace(u);
}
}
}
int ans = dep[(1 << N) - 1];
if (ans == -1) {
std::cout << "NO\n";
} else {
std::cout << "YES\n";
std::cout << ans << '\n';
int mask = (1 << N) - 1;
while (mask != 0) {
std::cerr << std::bitset<10>(mask) << '\n';
std::cout << bef[mask].second + 1 << ' ';
mask = bef[mask].first;
}
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 |
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 |
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 |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
508 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 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 |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
760 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
908 KB |
Output is correct |
30 |
Correct |
2 ms |
1276 KB |
Output is correct |
31 |
Correct |
2 ms |
1616 KB |
Output is correct |
32 |
Correct |
2 ms |
1616 KB |
Output is correct |
33 |
Correct |
3 ms |
1616 KB |
Output is correct |
34 |
Correct |
2 ms |
1616 KB |
Output is correct |
35 |
Correct |
3 ms |
2896 KB |
Output is correct |
36 |
Correct |
3 ms |
2852 KB |
Output is correct |
37 |
Correct |
3 ms |
2896 KB |
Output is correct |
38 |
Correct |
3 ms |
2820 KB |
Output is correct |
39 |
Correct |
4 ms |
5200 KB |
Output is correct |
40 |
Correct |
5 ms |
5200 KB |
Output is correct |
41 |
Correct |
4 ms |
5200 KB |
Output is correct |
42 |
Correct |
4 ms |
5200 KB |
Output is correct |
43 |
Correct |
6 ms |
10064 KB |
Output is correct |
44 |
Correct |
6 ms |
10232 KB |
Output is correct |
45 |
Correct |
8 ms |
10064 KB |
Output is correct |
46 |
Correct |
6 ms |
10064 KB |
Output is correct |
47 |
Correct |
5 ms |
19792 KB |
Output is correct |
48 |
Correct |
6 ms |
19792 KB |
Output is correct |
49 |
Correct |
5 ms |
19792 KB |
Output is correct |
50 |
Correct |
6 ms |
19792 KB |
Output is correct |
51 |
Correct |
8 ms |
39504 KB |
Output is correct |
52 |
Correct |
7 ms |
39504 KB |
Output is correct |
53 |
Correct |
8 ms |
39504 KB |
Output is correct |
54 |
Correct |
7 ms |
39504 KB |
Output is correct |
55 |
Correct |
14 ms |
78416 KB |
Output is correct |
56 |
Correct |
14 ms |
78416 KB |
Output is correct |
57 |
Correct |
14 ms |
78680 KB |
Output is correct |
58 |
Correct |
13 ms |
78416 KB |
Output is correct |
59 |
Correct |
14 ms |
78416 KB |
Output is correct |
60 |
Correct |
15 ms |
78432 KB |
Output is correct |
61 |
Correct |
14 ms |
78416 KB |
Output is correct |
62 |
Correct |
16 ms |
78416 KB |
Output is correct |
63 |
Correct |
15 ms |
78476 KB |
Output is correct |
64 |
Correct |
14 ms |
78468 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 |
384 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 |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Runtime error |
11 ms |
9040 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 |
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 |
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 |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
508 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 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 |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
1 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
760 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
908 KB |
Output is correct |
30 |
Correct |
2 ms |
1276 KB |
Output is correct |
31 |
Correct |
2 ms |
1616 KB |
Output is correct |
32 |
Correct |
2 ms |
1616 KB |
Output is correct |
33 |
Correct |
3 ms |
1616 KB |
Output is correct |
34 |
Correct |
2 ms |
1616 KB |
Output is correct |
35 |
Correct |
3 ms |
2896 KB |
Output is correct |
36 |
Correct |
3 ms |
2852 KB |
Output is correct |
37 |
Correct |
3 ms |
2896 KB |
Output is correct |
38 |
Correct |
3 ms |
2820 KB |
Output is correct |
39 |
Correct |
4 ms |
5200 KB |
Output is correct |
40 |
Correct |
5 ms |
5200 KB |
Output is correct |
41 |
Correct |
4 ms |
5200 KB |
Output is correct |
42 |
Correct |
4 ms |
5200 KB |
Output is correct |
43 |
Correct |
6 ms |
10064 KB |
Output is correct |
44 |
Correct |
6 ms |
10232 KB |
Output is correct |
45 |
Correct |
8 ms |
10064 KB |
Output is correct |
46 |
Correct |
6 ms |
10064 KB |
Output is correct |
47 |
Correct |
5 ms |
19792 KB |
Output is correct |
48 |
Correct |
6 ms |
19792 KB |
Output is correct |
49 |
Correct |
5 ms |
19792 KB |
Output is correct |
50 |
Correct |
6 ms |
19792 KB |
Output is correct |
51 |
Correct |
8 ms |
39504 KB |
Output is correct |
52 |
Correct |
7 ms |
39504 KB |
Output is correct |
53 |
Correct |
8 ms |
39504 KB |
Output is correct |
54 |
Correct |
7 ms |
39504 KB |
Output is correct |
55 |
Correct |
14 ms |
78416 KB |
Output is correct |
56 |
Correct |
14 ms |
78416 KB |
Output is correct |
57 |
Correct |
14 ms |
78680 KB |
Output is correct |
58 |
Correct |
13 ms |
78416 KB |
Output is correct |
59 |
Correct |
14 ms |
78416 KB |
Output is correct |
60 |
Correct |
15 ms |
78432 KB |
Output is correct |
61 |
Correct |
14 ms |
78416 KB |
Output is correct |
62 |
Correct |
16 ms |
78416 KB |
Output is correct |
63 |
Correct |
15 ms |
78476 KB |
Output is correct |
64 |
Correct |
14 ms |
78468 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 |
336 KB |
Output is correct |
69 |
Correct |
1 ms |
336 KB |
Output is correct |
70 |
Correct |
1 ms |
336 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
348 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 |
336 KB |
Output is correct |
77 |
Correct |
1 ms |
336 KB |
Output is correct |
78 |
Correct |
1 ms |
336 KB |
Output is correct |
79 |
Runtime error |
222 ms |
524288 KB |
Execution killed with signal 9 |
80 |
Halted |
0 ms |
0 KB |
- |