#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
vector<vector<int>> graph(N);
for (int i = 0; i < M; ++i) {
int a, b;
std::cin >> a >> b;
a -= 1, b -= 1;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<int> adj(1 << N);
for (int set = 0; set < (1 << N); ++set) {
for (int i = 0; i < N; ++i) {
if (set >> i & 1) {
for (const int j : graph[i]) {
adj[set] |= 1 << j;
}
}
}
}
vector<vector<pair<int, int>>> transit(1 << N);
for (int set = 0; set < (1 << N); ++set) {
for (int i = 0; i < N; ++i) {
transit[adj[set] & ~(1 << i)].emplace_back(set, i);
}
}
vector<int> dist(1 << N, -1), last(1 << N, -1);
std::queue<int> que;
const auto push = [&](const int u, const int d, const int l) {
if (dist[u] == -1) {
dist[u] = d;
last[u] = l;
que.push(u);
}
};
push(0, 0, -1);
while (!que.empty()) {
const int u = que.front();
que.pop();
for (const auto& [v, i] : transit[u]) {
push(v, dist[u] + 1, i);
}
}
int set = (1 << N) - 1;
if (dist[set] == -1) {
std::cout << "NO\n";
return 0;
}
std::cout << "YES\n";
std::cout << dist[set] << '\n';
while (set != 0) {
std::cout << last[set] + 1;
set = adj[set] & ~(1 << last[set]);
std::cout << " \n"[set == 0];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
1 ms |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
2 ms |
972 KB |
Output is correct |
24 |
Correct |
2 ms |
972 KB |
Output is correct |
25 |
Correct |
2 ms |
972 KB |
Output is correct |
26 |
Correct |
2 ms |
972 KB |
Output is correct |
27 |
Correct |
3 ms |
1868 KB |
Output is correct |
28 |
Correct |
3 ms |
1868 KB |
Output is correct |
29 |
Correct |
4 ms |
1868 KB |
Output is correct |
30 |
Correct |
4 ms |
1868 KB |
Output is correct |
31 |
Correct |
6 ms |
3388 KB |
Output is correct |
32 |
Correct |
7 ms |
3404 KB |
Output is correct |
33 |
Correct |
8 ms |
3532 KB |
Output is correct |
34 |
Correct |
5 ms |
3532 KB |
Output is correct |
35 |
Correct |
14 ms |
6732 KB |
Output is correct |
36 |
Correct |
15 ms |
7244 KB |
Output is correct |
37 |
Correct |
15 ms |
6972 KB |
Output is correct |
38 |
Correct |
16 ms |
6860 KB |
Output is correct |
39 |
Correct |
31 ms |
14384 KB |
Output is correct |
40 |
Correct |
33 ms |
13312 KB |
Output is correct |
41 |
Correct |
27 ms |
12868 KB |
Output is correct |
42 |
Correct |
31 ms |
14684 KB |
Output is correct |
43 |
Correct |
69 ms |
28860 KB |
Output is correct |
44 |
Correct |
55 ms |
28672 KB |
Output is correct |
45 |
Correct |
57 ms |
28464 KB |
Output is correct |
46 |
Correct |
65 ms |
30384 KB |
Output is correct |
47 |
Correct |
122 ms |
58564 KB |
Output is correct |
48 |
Correct |
134 ms |
60048 KB |
Output is correct |
49 |
Correct |
118 ms |
60704 KB |
Output is correct |
50 |
Correct |
124 ms |
61508 KB |
Output is correct |
51 |
Correct |
243 ms |
117416 KB |
Output is correct |
52 |
Correct |
238 ms |
121588 KB |
Output is correct |
53 |
Correct |
245 ms |
119488 KB |
Output is correct |
54 |
Correct |
262 ms |
116364 KB |
Output is correct |
55 |
Correct |
545 ms |
251356 KB |
Output is correct |
56 |
Correct |
460 ms |
228564 KB |
Output is correct |
57 |
Correct |
727 ms |
265032 KB |
Output is correct |
58 |
Correct |
650 ms |
255832 KB |
Output is correct |
59 |
Correct |
508 ms |
201692 KB |
Output is correct |
60 |
Correct |
475 ms |
202184 KB |
Output is correct |
61 |
Correct |
470 ms |
224516 KB |
Output is correct |
62 |
Correct |
495 ms |
222164 KB |
Output is correct |
63 |
Correct |
516 ms |
202064 KB |
Output is correct |
64 |
Correct |
528 ms |
201508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Runtime error |
80 ms |
4208 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
588 KB |
Output is correct |
21 |
Correct |
1 ms |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
2 ms |
972 KB |
Output is correct |
24 |
Correct |
2 ms |
972 KB |
Output is correct |
25 |
Correct |
2 ms |
972 KB |
Output is correct |
26 |
Correct |
2 ms |
972 KB |
Output is correct |
27 |
Correct |
3 ms |
1868 KB |
Output is correct |
28 |
Correct |
3 ms |
1868 KB |
Output is correct |
29 |
Correct |
4 ms |
1868 KB |
Output is correct |
30 |
Correct |
4 ms |
1868 KB |
Output is correct |
31 |
Correct |
6 ms |
3388 KB |
Output is correct |
32 |
Correct |
7 ms |
3404 KB |
Output is correct |
33 |
Correct |
8 ms |
3532 KB |
Output is correct |
34 |
Correct |
5 ms |
3532 KB |
Output is correct |
35 |
Correct |
14 ms |
6732 KB |
Output is correct |
36 |
Correct |
15 ms |
7244 KB |
Output is correct |
37 |
Correct |
15 ms |
6972 KB |
Output is correct |
38 |
Correct |
16 ms |
6860 KB |
Output is correct |
39 |
Correct |
31 ms |
14384 KB |
Output is correct |
40 |
Correct |
33 ms |
13312 KB |
Output is correct |
41 |
Correct |
27 ms |
12868 KB |
Output is correct |
42 |
Correct |
31 ms |
14684 KB |
Output is correct |
43 |
Correct |
69 ms |
28860 KB |
Output is correct |
44 |
Correct |
55 ms |
28672 KB |
Output is correct |
45 |
Correct |
57 ms |
28464 KB |
Output is correct |
46 |
Correct |
65 ms |
30384 KB |
Output is correct |
47 |
Correct |
122 ms |
58564 KB |
Output is correct |
48 |
Correct |
134 ms |
60048 KB |
Output is correct |
49 |
Correct |
118 ms |
60704 KB |
Output is correct |
50 |
Correct |
124 ms |
61508 KB |
Output is correct |
51 |
Correct |
243 ms |
117416 KB |
Output is correct |
52 |
Correct |
238 ms |
121588 KB |
Output is correct |
53 |
Correct |
245 ms |
119488 KB |
Output is correct |
54 |
Correct |
262 ms |
116364 KB |
Output is correct |
55 |
Correct |
545 ms |
251356 KB |
Output is correct |
56 |
Correct |
460 ms |
228564 KB |
Output is correct |
57 |
Correct |
727 ms |
265032 KB |
Output is correct |
58 |
Correct |
650 ms |
255832 KB |
Output is correct |
59 |
Correct |
508 ms |
201692 KB |
Output is correct |
60 |
Correct |
475 ms |
202184 KB |
Output is correct |
61 |
Correct |
470 ms |
224516 KB |
Output is correct |
62 |
Correct |
495 ms |
222164 KB |
Output is correct |
63 |
Correct |
516 ms |
202064 KB |
Output is correct |
64 |
Correct |
528 ms |
201508 KB |
Output is correct |
65 |
Correct |
0 ms |
312 KB |
Output is correct |
66 |
Correct |
0 ms |
204 KB |
Output is correct |
67 |
Correct |
1 ms |
204 KB |
Output is correct |
68 |
Correct |
1 ms |
312 KB |
Output is correct |
69 |
Correct |
0 ms |
204 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
1 ms |
312 KB |
Output is correct |
73 |
Correct |
1 ms |
440 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
1 ms |
332 KB |
Output is correct |
76 |
Correct |
1 ms |
332 KB |
Output is correct |
77 |
Correct |
0 ms |
332 KB |
Output is correct |
78 |
Correct |
0 ms |
316 KB |
Output is correct |
79 |
Runtime error |
199 ms |
524292 KB |
Execution killed with signal 9 |
80 |
Halted |
0 ms |
0 KB |
- |