#include "bits/stdc++.h"
using namespace std;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
if(p==0) return 1 % MOD;
int r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int inv(int b) {
return bm(b, MOD-2);
}
int fastlog(int x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
vector<int> adj[1029];
int state[(1 << 20)];
bool vis[(1 << 20)];
pair<int, int> pv[(1 << 20)];
vector<pair<int, int> > trans[(1 << 20)];
int msk[21];
void solve(int tc) {
int n, m; cin >> n >> m;
for(int i=0; i<(1<<n)-1; i++) state[i] = 1e9;
state[(1<<n)-1] = 0;
for(int i=0; i<m; i++) {
int u, v; cin >> u >> v;
u--, v--;
msk[u] |= (1 << v);
msk[v] |= (1 << u);
}
for(int i=0; i<(1<<n); i++) {
int nxt= 0;
for(int j=0; j<n; j++) {
if(i & (1<<j)) {
nxt |= msk[j];
}
}
for(int j=0; j<n; j++) {
int rl = nxt | (1<<j);
rl ^= (1<<j);
trans[i].push_back({rl, j});
}
}
queue<int> q;
q.push((1<<n) - 1);
while(q.size()) {
int f=q.front(); q.pop();
if(!vis[f]) {
vis[f] = 1;
for(pair<int, int> x: trans[f]) {
if(!vis[x.first] && state[x.first]>state[f] + 1) {
state[x.first] = state[f] + 1;
pv[x.first] = {f, x.second};
q.push(x.first);
}
}
}
}
cout << (state[0] == 1e9 ? "NO\n" : "YES\n");
if(state[0] == 1e9) return;
int cur = 0;
stack<int> stk;
while(cur != (1<<n) - 1) {
stk.push(pv[cur].second + 1);
cur = pv[cur].first;
}
cout << stk.size() << "\n";
while(stk.size()) {
int ss=stk.top(); stk.pop();
cout << ss;
if(stk.size()) cout << " ";
else cout << "\n";
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24940 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
13 ms |
24904 KB |
Output is correct |
6 |
Correct |
13 ms |
25004 KB |
Output is correct |
7 |
Correct |
13 ms |
24916 KB |
Output is correct |
8 |
Correct |
13 ms |
24932 KB |
Output is correct |
9 |
Correct |
14 ms |
25044 KB |
Output is correct |
10 |
Correct |
13 ms |
25044 KB |
Output is correct |
11 |
Correct |
13 ms |
24916 KB |
Output is correct |
12 |
Correct |
13 ms |
24976 KB |
Output is correct |
13 |
Correct |
15 ms |
24940 KB |
Output is correct |
14 |
Correct |
13 ms |
24936 KB |
Output is correct |
15 |
Correct |
13 ms |
25044 KB |
Output is correct |
16 |
Correct |
14 ms |
25076 KB |
Output is correct |
17 |
Correct |
13 ms |
25064 KB |
Output is correct |
18 |
Correct |
12 ms |
25068 KB |
Output is correct |
19 |
Correct |
13 ms |
25300 KB |
Output is correct |
20 |
Correct |
13 ms |
25280 KB |
Output is correct |
21 |
Correct |
13 ms |
25300 KB |
Output is correct |
22 |
Correct |
14 ms |
25300 KB |
Output is correct |
23 |
Correct |
14 ms |
25568 KB |
Output is correct |
24 |
Correct |
15 ms |
25556 KB |
Output is correct |
25 |
Correct |
14 ms |
25556 KB |
Output is correct |
26 |
Correct |
13 ms |
25552 KB |
Output is correct |
27 |
Correct |
15 ms |
26132 KB |
Output is correct |
28 |
Correct |
15 ms |
26196 KB |
Output is correct |
29 |
Correct |
17 ms |
26240 KB |
Output is correct |
30 |
Correct |
15 ms |
26208 KB |
Output is correct |
31 |
Correct |
19 ms |
27476 KB |
Output is correct |
32 |
Correct |
20 ms |
27452 KB |
Output is correct |
33 |
Correct |
17 ms |
27476 KB |
Output is correct |
34 |
Correct |
17 ms |
27436 KB |
Output is correct |
35 |
Correct |
22 ms |
29940 KB |
Output is correct |
36 |
Correct |
22 ms |
29904 KB |
Output is correct |
37 |
Correct |
22 ms |
30020 KB |
Output is correct |
38 |
Correct |
22 ms |
29960 KB |
Output is correct |
39 |
Correct |
32 ms |
35020 KB |
Output is correct |
40 |
Correct |
32 ms |
35028 KB |
Output is correct |
41 |
Correct |
32 ms |
34772 KB |
Output is correct |
42 |
Correct |
33 ms |
34948 KB |
Output is correct |
43 |
Correct |
65 ms |
61248 KB |
Output is correct |
44 |
Correct |
64 ms |
61004 KB |
Output is correct |
45 |
Correct |
62 ms |
61044 KB |
Output is correct |
46 |
Correct |
63 ms |
61044 KB |
Output is correct |
47 |
Correct |
111 ms |
96920 KB |
Output is correct |
48 |
Correct |
118 ms |
97412 KB |
Output is correct |
49 |
Correct |
113 ms |
96744 KB |
Output is correct |
50 |
Correct |
114 ms |
96776 KB |
Output is correct |
51 |
Correct |
209 ms |
168892 KB |
Output is correct |
52 |
Correct |
210 ms |
167808 KB |
Output is correct |
53 |
Correct |
208 ms |
168144 KB |
Output is correct |
54 |
Correct |
209 ms |
168524 KB |
Output is correct |
55 |
Correct |
422 ms |
310124 KB |
Output is correct |
56 |
Correct |
406 ms |
309336 KB |
Output is correct |
57 |
Correct |
409 ms |
311320 KB |
Output is correct |
58 |
Correct |
410 ms |
310212 KB |
Output is correct |
59 |
Correct |
411 ms |
308224 KB |
Output is correct |
60 |
Correct |
410 ms |
308156 KB |
Output is correct |
61 |
Correct |
409 ms |
308200 KB |
Output is correct |
62 |
Correct |
419 ms |
308224 KB |
Output is correct |
63 |
Correct |
409 ms |
308204 KB |
Output is correct |
64 |
Correct |
409 ms |
308144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24964 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
14 ms |
24996 KB |
Output is correct |
5 |
Correct |
13 ms |
24916 KB |
Output is correct |
6 |
Correct |
13 ms |
24916 KB |
Output is correct |
7 |
Correct |
13 ms |
24916 KB |
Output is correct |
8 |
Correct |
13 ms |
24916 KB |
Output is correct |
9 |
Correct |
13 ms |
25016 KB |
Output is correct |
10 |
Correct |
13 ms |
25028 KB |
Output is correct |
11 |
Runtime error |
34 ms |
50864 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24940 KB |
Output is correct |
3 |
Correct |
13 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
13 ms |
24904 KB |
Output is correct |
6 |
Correct |
13 ms |
25004 KB |
Output is correct |
7 |
Correct |
13 ms |
24916 KB |
Output is correct |
8 |
Correct |
13 ms |
24932 KB |
Output is correct |
9 |
Correct |
14 ms |
25044 KB |
Output is correct |
10 |
Correct |
13 ms |
25044 KB |
Output is correct |
11 |
Correct |
13 ms |
24916 KB |
Output is correct |
12 |
Correct |
13 ms |
24976 KB |
Output is correct |
13 |
Correct |
15 ms |
24940 KB |
Output is correct |
14 |
Correct |
13 ms |
24936 KB |
Output is correct |
15 |
Correct |
13 ms |
25044 KB |
Output is correct |
16 |
Correct |
14 ms |
25076 KB |
Output is correct |
17 |
Correct |
13 ms |
25064 KB |
Output is correct |
18 |
Correct |
12 ms |
25068 KB |
Output is correct |
19 |
Correct |
13 ms |
25300 KB |
Output is correct |
20 |
Correct |
13 ms |
25280 KB |
Output is correct |
21 |
Correct |
13 ms |
25300 KB |
Output is correct |
22 |
Correct |
14 ms |
25300 KB |
Output is correct |
23 |
Correct |
14 ms |
25568 KB |
Output is correct |
24 |
Correct |
15 ms |
25556 KB |
Output is correct |
25 |
Correct |
14 ms |
25556 KB |
Output is correct |
26 |
Correct |
13 ms |
25552 KB |
Output is correct |
27 |
Correct |
15 ms |
26132 KB |
Output is correct |
28 |
Correct |
15 ms |
26196 KB |
Output is correct |
29 |
Correct |
17 ms |
26240 KB |
Output is correct |
30 |
Correct |
15 ms |
26208 KB |
Output is correct |
31 |
Correct |
19 ms |
27476 KB |
Output is correct |
32 |
Correct |
20 ms |
27452 KB |
Output is correct |
33 |
Correct |
17 ms |
27476 KB |
Output is correct |
34 |
Correct |
17 ms |
27436 KB |
Output is correct |
35 |
Correct |
22 ms |
29940 KB |
Output is correct |
36 |
Correct |
22 ms |
29904 KB |
Output is correct |
37 |
Correct |
22 ms |
30020 KB |
Output is correct |
38 |
Correct |
22 ms |
29960 KB |
Output is correct |
39 |
Correct |
32 ms |
35020 KB |
Output is correct |
40 |
Correct |
32 ms |
35028 KB |
Output is correct |
41 |
Correct |
32 ms |
34772 KB |
Output is correct |
42 |
Correct |
33 ms |
34948 KB |
Output is correct |
43 |
Correct |
65 ms |
61248 KB |
Output is correct |
44 |
Correct |
64 ms |
61004 KB |
Output is correct |
45 |
Correct |
62 ms |
61044 KB |
Output is correct |
46 |
Correct |
63 ms |
61044 KB |
Output is correct |
47 |
Correct |
111 ms |
96920 KB |
Output is correct |
48 |
Correct |
118 ms |
97412 KB |
Output is correct |
49 |
Correct |
113 ms |
96744 KB |
Output is correct |
50 |
Correct |
114 ms |
96776 KB |
Output is correct |
51 |
Correct |
209 ms |
168892 KB |
Output is correct |
52 |
Correct |
210 ms |
167808 KB |
Output is correct |
53 |
Correct |
208 ms |
168144 KB |
Output is correct |
54 |
Correct |
209 ms |
168524 KB |
Output is correct |
55 |
Correct |
422 ms |
310124 KB |
Output is correct |
56 |
Correct |
406 ms |
309336 KB |
Output is correct |
57 |
Correct |
409 ms |
311320 KB |
Output is correct |
58 |
Correct |
410 ms |
310212 KB |
Output is correct |
59 |
Correct |
411 ms |
308224 KB |
Output is correct |
60 |
Correct |
410 ms |
308156 KB |
Output is correct |
61 |
Correct |
409 ms |
308200 KB |
Output is correct |
62 |
Correct |
419 ms |
308224 KB |
Output is correct |
63 |
Correct |
409 ms |
308204 KB |
Output is correct |
64 |
Correct |
409 ms |
308144 KB |
Output is correct |
65 |
Correct |
13 ms |
24916 KB |
Output is correct |
66 |
Correct |
12 ms |
24916 KB |
Output is correct |
67 |
Correct |
15 ms |
24916 KB |
Output is correct |
68 |
Correct |
13 ms |
24964 KB |
Output is correct |
69 |
Correct |
13 ms |
24916 KB |
Output is correct |
70 |
Correct |
13 ms |
24916 KB |
Output is correct |
71 |
Correct |
13 ms |
24916 KB |
Output is correct |
72 |
Correct |
13 ms |
24916 KB |
Output is correct |
73 |
Correct |
13 ms |
25104 KB |
Output is correct |
74 |
Correct |
13 ms |
25044 KB |
Output is correct |
75 |
Correct |
13 ms |
24980 KB |
Output is correct |
76 |
Correct |
14 ms |
24916 KB |
Output is correct |
77 |
Correct |
13 ms |
24980 KB |
Output is correct |
78 |
Correct |
14 ms |
24980 KB |
Output is correct |
79 |
Runtime error |
39 ms |
58692 KB |
Execution killed with signal 11 |
80 |
Halted |
0 ms |
0 KB |
- |