#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 << ": "; }
int state[(1 << 20)];
bool vis[(1 << 20)];
pair<int, int> pv[(1 << 20)];
vector<pair<int, int> > trans[(1 << 20)];
int msk[1029];
void solve(int tc) {
int n, m;
cin >> n >> m;
if(n > 20) {
cout << "YES\n";
cout << n * 2 - 4 << "\n";
if(n & 1) {
for(int i=2; i<n; i++) cout << i << " ";
for(int i=2; i<n; i++) cout << i << " ";
}
else {
for(int i=2; i<n; i++) cout << i << " ";
for(int i=n-1; i>=2; i--) cout << i << " ";
}
cout << "\n";
return;
}
for(int i=0; i<(1<<n)-1; i++) state[i] = 1e9;
state[(1<<n)-1] = 0;
vector<pair<int, int>> edges;
for(int i=0; i<m; i++) {
int u, v;
cin >> u >> v;
edges.push_back({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 |
15 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
24916 KB |
Output is correct |
3 |
Correct |
15 ms |
24916 KB |
Output is correct |
4 |
Correct |
12 ms |
24916 KB |
Output is correct |
5 |
Correct |
17 ms |
24956 KB |
Output is correct |
6 |
Correct |
21 ms |
24916 KB |
Output is correct |
7 |
Correct |
16 ms |
24972 KB |
Output is correct |
8 |
Correct |
12 ms |
24916 KB |
Output is correct |
9 |
Correct |
12 ms |
25128 KB |
Output is correct |
10 |
Correct |
15 ms |
25044 KB |
Output is correct |
11 |
Correct |
14 ms |
24916 KB |
Output is correct |
12 |
Correct |
14 ms |
24956 KB |
Output is correct |
13 |
Correct |
13 ms |
24916 KB |
Output is correct |
14 |
Correct |
21 ms |
24944 KB |
Output is correct |
15 |
Correct |
23 ms |
25044 KB |
Output is correct |
16 |
Correct |
12 ms |
25104 KB |
Output is correct |
17 |
Correct |
13 ms |
25084 KB |
Output is correct |
18 |
Correct |
12 ms |
25036 KB |
Output is correct |
19 |
Correct |
13 ms |
25188 KB |
Output is correct |
20 |
Correct |
13 ms |
25172 KB |
Output is correct |
21 |
Correct |
13 ms |
25172 KB |
Output is correct |
22 |
Correct |
13 ms |
25172 KB |
Output is correct |
23 |
Correct |
13 ms |
25556 KB |
Output is correct |
24 |
Correct |
15 ms |
25580 KB |
Output is correct |
25 |
Correct |
13 ms |
25588 KB |
Output is correct |
26 |
Correct |
13 ms |
25480 KB |
Output is correct |
27 |
Correct |
14 ms |
26196 KB |
Output is correct |
28 |
Correct |
14 ms |
26108 KB |
Output is correct |
29 |
Correct |
15 ms |
26144 KB |
Output is correct |
30 |
Correct |
14 ms |
26196 KB |
Output is correct |
31 |
Correct |
16 ms |
27476 KB |
Output is correct |
32 |
Correct |
16 ms |
27492 KB |
Output is correct |
33 |
Correct |
18 ms |
27476 KB |
Output is correct |
34 |
Correct |
33 ms |
27404 KB |
Output is correct |
35 |
Correct |
23 ms |
29908 KB |
Output is correct |
36 |
Correct |
20 ms |
29908 KB |
Output is correct |
37 |
Correct |
20 ms |
29896 KB |
Output is correct |
38 |
Correct |
21 ms |
29908 KB |
Output is correct |
39 |
Correct |
30 ms |
34932 KB |
Output is correct |
40 |
Correct |
30 ms |
35012 KB |
Output is correct |
41 |
Correct |
29 ms |
34732 KB |
Output is correct |
42 |
Correct |
30 ms |
34892 KB |
Output is correct |
43 |
Correct |
65 ms |
61248 KB |
Output is correct |
44 |
Correct |
64 ms |
61048 KB |
Output is correct |
45 |
Correct |
63 ms |
61032 KB |
Output is correct |
46 |
Correct |
63 ms |
61004 KB |
Output is correct |
47 |
Correct |
118 ms |
97040 KB |
Output is correct |
48 |
Correct |
135 ms |
97576 KB |
Output is correct |
49 |
Correct |
113 ms |
96648 KB |
Output is correct |
50 |
Correct |
129 ms |
96776 KB |
Output is correct |
51 |
Correct |
233 ms |
169164 KB |
Output is correct |
52 |
Correct |
221 ms |
167884 KB |
Output is correct |
53 |
Correct |
217 ms |
168052 KB |
Output is correct |
54 |
Correct |
220 ms |
168520 KB |
Output is correct |
55 |
Correct |
420 ms |
310200 KB |
Output is correct |
56 |
Correct |
476 ms |
309240 KB |
Output is correct |
57 |
Correct |
443 ms |
311332 KB |
Output is correct |
58 |
Correct |
483 ms |
310300 KB |
Output is correct |
59 |
Correct |
552 ms |
308144 KB |
Output is correct |
60 |
Correct |
468 ms |
308320 KB |
Output is correct |
61 |
Correct |
506 ms |
308172 KB |
Output is correct |
62 |
Correct |
465 ms |
308208 KB |
Output is correct |
63 |
Correct |
440 ms |
308212 KB |
Output is correct |
64 |
Correct |
527 ms |
308208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
24964 KB |
Output is correct |
2 |
Correct |
17 ms |
24960 KB |
Output is correct |
3 |
Correct |
15 ms |
24956 KB |
Output is correct |
4 |
Correct |
18 ms |
24916 KB |
Output is correct |
5 |
Correct |
17 ms |
24968 KB |
Output is correct |
6 |
Correct |
16 ms |
24904 KB |
Output is correct |
7 |
Correct |
15 ms |
24916 KB |
Output is correct |
8 |
Correct |
15 ms |
24960 KB |
Output is correct |
9 |
Correct |
15 ms |
24964 KB |
Output is correct |
10 |
Correct |
16 ms |
25096 KB |
Output is correct |
11 |
Correct |
18 ms |
24916 KB |
Output is correct |
12 |
Correct |
14 ms |
24852 KB |
Output is correct |
13 |
Correct |
15 ms |
24884 KB |
Output is correct |
14 |
Correct |
14 ms |
24964 KB |
Output is correct |
15 |
Correct |
15 ms |
24964 KB |
Output is correct |
16 |
Correct |
19 ms |
24872 KB |
Output is correct |
17 |
Correct |
14 ms |
24960 KB |
Output is correct |
18 |
Correct |
14 ms |
24916 KB |
Output is correct |
19 |
Correct |
14 ms |
24968 KB |
Output is correct |
20 |
Correct |
16 ms |
24868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
24916 KB |
Output is correct |
3 |
Correct |
15 ms |
24916 KB |
Output is correct |
4 |
Correct |
12 ms |
24916 KB |
Output is correct |
5 |
Correct |
17 ms |
24956 KB |
Output is correct |
6 |
Correct |
21 ms |
24916 KB |
Output is correct |
7 |
Correct |
16 ms |
24972 KB |
Output is correct |
8 |
Correct |
12 ms |
24916 KB |
Output is correct |
9 |
Correct |
12 ms |
25128 KB |
Output is correct |
10 |
Correct |
15 ms |
25044 KB |
Output is correct |
11 |
Correct |
14 ms |
24916 KB |
Output is correct |
12 |
Correct |
14 ms |
24956 KB |
Output is correct |
13 |
Correct |
13 ms |
24916 KB |
Output is correct |
14 |
Correct |
21 ms |
24944 KB |
Output is correct |
15 |
Correct |
23 ms |
25044 KB |
Output is correct |
16 |
Correct |
12 ms |
25104 KB |
Output is correct |
17 |
Correct |
13 ms |
25084 KB |
Output is correct |
18 |
Correct |
12 ms |
25036 KB |
Output is correct |
19 |
Correct |
13 ms |
25188 KB |
Output is correct |
20 |
Correct |
13 ms |
25172 KB |
Output is correct |
21 |
Correct |
13 ms |
25172 KB |
Output is correct |
22 |
Correct |
13 ms |
25172 KB |
Output is correct |
23 |
Correct |
13 ms |
25556 KB |
Output is correct |
24 |
Correct |
15 ms |
25580 KB |
Output is correct |
25 |
Correct |
13 ms |
25588 KB |
Output is correct |
26 |
Correct |
13 ms |
25480 KB |
Output is correct |
27 |
Correct |
14 ms |
26196 KB |
Output is correct |
28 |
Correct |
14 ms |
26108 KB |
Output is correct |
29 |
Correct |
15 ms |
26144 KB |
Output is correct |
30 |
Correct |
14 ms |
26196 KB |
Output is correct |
31 |
Correct |
16 ms |
27476 KB |
Output is correct |
32 |
Correct |
16 ms |
27492 KB |
Output is correct |
33 |
Correct |
18 ms |
27476 KB |
Output is correct |
34 |
Correct |
33 ms |
27404 KB |
Output is correct |
35 |
Correct |
23 ms |
29908 KB |
Output is correct |
36 |
Correct |
20 ms |
29908 KB |
Output is correct |
37 |
Correct |
20 ms |
29896 KB |
Output is correct |
38 |
Correct |
21 ms |
29908 KB |
Output is correct |
39 |
Correct |
30 ms |
34932 KB |
Output is correct |
40 |
Correct |
30 ms |
35012 KB |
Output is correct |
41 |
Correct |
29 ms |
34732 KB |
Output is correct |
42 |
Correct |
30 ms |
34892 KB |
Output is correct |
43 |
Correct |
65 ms |
61248 KB |
Output is correct |
44 |
Correct |
64 ms |
61048 KB |
Output is correct |
45 |
Correct |
63 ms |
61032 KB |
Output is correct |
46 |
Correct |
63 ms |
61004 KB |
Output is correct |
47 |
Correct |
118 ms |
97040 KB |
Output is correct |
48 |
Correct |
135 ms |
97576 KB |
Output is correct |
49 |
Correct |
113 ms |
96648 KB |
Output is correct |
50 |
Correct |
129 ms |
96776 KB |
Output is correct |
51 |
Correct |
233 ms |
169164 KB |
Output is correct |
52 |
Correct |
221 ms |
167884 KB |
Output is correct |
53 |
Correct |
217 ms |
168052 KB |
Output is correct |
54 |
Correct |
220 ms |
168520 KB |
Output is correct |
55 |
Correct |
420 ms |
310200 KB |
Output is correct |
56 |
Correct |
476 ms |
309240 KB |
Output is correct |
57 |
Correct |
443 ms |
311332 KB |
Output is correct |
58 |
Correct |
483 ms |
310300 KB |
Output is correct |
59 |
Correct |
552 ms |
308144 KB |
Output is correct |
60 |
Correct |
468 ms |
308320 KB |
Output is correct |
61 |
Correct |
506 ms |
308172 KB |
Output is correct |
62 |
Correct |
465 ms |
308208 KB |
Output is correct |
63 |
Correct |
440 ms |
308212 KB |
Output is correct |
64 |
Correct |
527 ms |
308208 KB |
Output is correct |
65 |
Correct |
17 ms |
24976 KB |
Output is correct |
66 |
Correct |
15 ms |
24916 KB |
Output is correct |
67 |
Correct |
16 ms |
24960 KB |
Output is correct |
68 |
Correct |
15 ms |
24916 KB |
Output is correct |
69 |
Correct |
17 ms |
24964 KB |
Output is correct |
70 |
Correct |
15 ms |
24956 KB |
Output is correct |
71 |
Correct |
13 ms |
24960 KB |
Output is correct |
72 |
Correct |
15 ms |
24936 KB |
Output is correct |
73 |
Correct |
14 ms |
25044 KB |
Output is correct |
74 |
Correct |
16 ms |
24980 KB |
Output is correct |
75 |
Correct |
17 ms |
24924 KB |
Output is correct |
76 |
Correct |
15 ms |
24892 KB |
Output is correct |
77 |
Correct |
14 ms |
24916 KB |
Output is correct |
78 |
Correct |
22 ms |
24920 KB |
Output is correct |
79 |
Incorrect |
14 ms |
24896 KB |
Output isn't correct |
80 |
Halted |
0 ms |
0 KB |
- |