#include "bits/stdc++.h"
using namespace std;
#define int long long
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
24964 KB |
Output is correct |
3 |
Correct |
15 ms |
24900 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
13 ms |
24916 KB |
Output is correct |
6 |
Correct |
14 ms |
24916 KB |
Output is correct |
7 |
Correct |
13 ms |
24996 KB |
Output is correct |
8 |
Correct |
13 ms |
24968 KB |
Output is correct |
9 |
Correct |
14 ms |
25172 KB |
Output is correct |
10 |
Correct |
13 ms |
25084 KB |
Output is correct |
11 |
Correct |
14 ms |
24916 KB |
Output is correct |
12 |
Correct |
14 ms |
24916 KB |
Output is correct |
13 |
Correct |
13 ms |
24964 KB |
Output is correct |
14 |
Correct |
15 ms |
24900 KB |
Output is correct |
15 |
Correct |
15 ms |
25212 KB |
Output is correct |
16 |
Correct |
14 ms |
25172 KB |
Output is correct |
17 |
Correct |
14 ms |
25172 KB |
Output is correct |
18 |
Correct |
14 ms |
25172 KB |
Output is correct |
19 |
Correct |
15 ms |
25556 KB |
Output is correct |
20 |
Correct |
15 ms |
25568 KB |
Output is correct |
21 |
Correct |
14 ms |
25556 KB |
Output is correct |
22 |
Correct |
15 ms |
25548 KB |
Output is correct |
23 |
Correct |
15 ms |
26068 KB |
Output is correct |
24 |
Correct |
14 ms |
26068 KB |
Output is correct |
25 |
Correct |
15 ms |
26068 KB |
Output is correct |
26 |
Correct |
15 ms |
26112 KB |
Output is correct |
27 |
Correct |
16 ms |
27264 KB |
Output is correct |
28 |
Correct |
17 ms |
27272 KB |
Output is correct |
29 |
Correct |
18 ms |
27252 KB |
Output is correct |
30 |
Correct |
16 ms |
27264 KB |
Output is correct |
31 |
Correct |
18 ms |
29668 KB |
Output is correct |
32 |
Correct |
19 ms |
29700 KB |
Output is correct |
33 |
Correct |
19 ms |
29652 KB |
Output is correct |
34 |
Correct |
19 ms |
29696 KB |
Output is correct |
35 |
Correct |
24 ms |
34456 KB |
Output is correct |
36 |
Correct |
24 ms |
34380 KB |
Output is correct |
37 |
Correct |
24 ms |
34388 KB |
Output is correct |
38 |
Correct |
24 ms |
34372 KB |
Output is correct |
39 |
Correct |
35 ms |
43748 KB |
Output is correct |
40 |
Correct |
35 ms |
43872 KB |
Output is correct |
41 |
Correct |
36 ms |
43468 KB |
Output is correct |
42 |
Correct |
35 ms |
43860 KB |
Output is correct |
43 |
Correct |
85 ms |
94992 KB |
Output is correct |
44 |
Correct |
77 ms |
94764 KB |
Output is correct |
45 |
Correct |
82 ms |
94648 KB |
Output is correct |
46 |
Correct |
82 ms |
94668 KB |
Output is correct |
47 |
Correct |
148 ms |
164080 KB |
Output is correct |
48 |
Correct |
142 ms |
164856 KB |
Output is correct |
49 |
Correct |
150 ms |
163676 KB |
Output is correct |
50 |
Correct |
143 ms |
163804 KB |
Output is correct |
51 |
Correct |
261 ms |
303032 KB |
Output is correct |
52 |
Correct |
270 ms |
302044 KB |
Output is correct |
53 |
Correct |
266 ms |
301844 KB |
Output is correct |
54 |
Correct |
269 ms |
302392 KB |
Output is correct |
55 |
Runtime error |
450 ms |
524288 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24904 KB |
Output is correct |
2 |
Correct |
12 ms |
24952 KB |
Output is correct |
3 |
Correct |
14 ms |
24868 KB |
Output is correct |
4 |
Correct |
15 ms |
24880 KB |
Output is correct |
5 |
Correct |
13 ms |
24916 KB |
Output is correct |
6 |
Correct |
13 ms |
24948 KB |
Output is correct |
7 |
Correct |
15 ms |
24960 KB |
Output is correct |
8 |
Correct |
14 ms |
24964 KB |
Output is correct |
9 |
Correct |
15 ms |
25044 KB |
Output is correct |
10 |
Correct |
15 ms |
25216 KB |
Output is correct |
11 |
Correct |
15 ms |
24964 KB |
Output is correct |
12 |
Correct |
15 ms |
24916 KB |
Output is correct |
13 |
Correct |
13 ms |
24916 KB |
Output is correct |
14 |
Correct |
13 ms |
24964 KB |
Output is correct |
15 |
Correct |
15 ms |
24968 KB |
Output is correct |
16 |
Correct |
13 ms |
24968 KB |
Output is correct |
17 |
Correct |
13 ms |
24916 KB |
Output is correct |
18 |
Correct |
13 ms |
24936 KB |
Output is correct |
19 |
Correct |
13 ms |
24944 KB |
Output is correct |
20 |
Correct |
14 ms |
24968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
14 ms |
24964 KB |
Output is correct |
3 |
Correct |
15 ms |
24900 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
13 ms |
24916 KB |
Output is correct |
6 |
Correct |
14 ms |
24916 KB |
Output is correct |
7 |
Correct |
13 ms |
24996 KB |
Output is correct |
8 |
Correct |
13 ms |
24968 KB |
Output is correct |
9 |
Correct |
14 ms |
25172 KB |
Output is correct |
10 |
Correct |
13 ms |
25084 KB |
Output is correct |
11 |
Correct |
14 ms |
24916 KB |
Output is correct |
12 |
Correct |
14 ms |
24916 KB |
Output is correct |
13 |
Correct |
13 ms |
24964 KB |
Output is correct |
14 |
Correct |
15 ms |
24900 KB |
Output is correct |
15 |
Correct |
15 ms |
25212 KB |
Output is correct |
16 |
Correct |
14 ms |
25172 KB |
Output is correct |
17 |
Correct |
14 ms |
25172 KB |
Output is correct |
18 |
Correct |
14 ms |
25172 KB |
Output is correct |
19 |
Correct |
15 ms |
25556 KB |
Output is correct |
20 |
Correct |
15 ms |
25568 KB |
Output is correct |
21 |
Correct |
14 ms |
25556 KB |
Output is correct |
22 |
Correct |
15 ms |
25548 KB |
Output is correct |
23 |
Correct |
15 ms |
26068 KB |
Output is correct |
24 |
Correct |
14 ms |
26068 KB |
Output is correct |
25 |
Correct |
15 ms |
26068 KB |
Output is correct |
26 |
Correct |
15 ms |
26112 KB |
Output is correct |
27 |
Correct |
16 ms |
27264 KB |
Output is correct |
28 |
Correct |
17 ms |
27272 KB |
Output is correct |
29 |
Correct |
18 ms |
27252 KB |
Output is correct |
30 |
Correct |
16 ms |
27264 KB |
Output is correct |
31 |
Correct |
18 ms |
29668 KB |
Output is correct |
32 |
Correct |
19 ms |
29700 KB |
Output is correct |
33 |
Correct |
19 ms |
29652 KB |
Output is correct |
34 |
Correct |
19 ms |
29696 KB |
Output is correct |
35 |
Correct |
24 ms |
34456 KB |
Output is correct |
36 |
Correct |
24 ms |
34380 KB |
Output is correct |
37 |
Correct |
24 ms |
34388 KB |
Output is correct |
38 |
Correct |
24 ms |
34372 KB |
Output is correct |
39 |
Correct |
35 ms |
43748 KB |
Output is correct |
40 |
Correct |
35 ms |
43872 KB |
Output is correct |
41 |
Correct |
36 ms |
43468 KB |
Output is correct |
42 |
Correct |
35 ms |
43860 KB |
Output is correct |
43 |
Correct |
85 ms |
94992 KB |
Output is correct |
44 |
Correct |
77 ms |
94764 KB |
Output is correct |
45 |
Correct |
82 ms |
94648 KB |
Output is correct |
46 |
Correct |
82 ms |
94668 KB |
Output is correct |
47 |
Correct |
148 ms |
164080 KB |
Output is correct |
48 |
Correct |
142 ms |
164856 KB |
Output is correct |
49 |
Correct |
150 ms |
163676 KB |
Output is correct |
50 |
Correct |
143 ms |
163804 KB |
Output is correct |
51 |
Correct |
261 ms |
303032 KB |
Output is correct |
52 |
Correct |
270 ms |
302044 KB |
Output is correct |
53 |
Correct |
266 ms |
301844 KB |
Output is correct |
54 |
Correct |
269 ms |
302392 KB |
Output is correct |
55 |
Runtime error |
450 ms |
524288 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |