#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 << ": "; }
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
12 ms |
24996 KB |
Output is correct |
3 |
Correct |
15 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
12 ms |
24916 KB |
Output is correct |
6 |
Correct |
12 ms |
24900 KB |
Output is correct |
7 |
Correct |
12 ms |
24912 KB |
Output is correct |
8 |
Correct |
14 ms |
24916 KB |
Output is correct |
9 |
Correct |
14 ms |
25172 KB |
Output is correct |
10 |
Correct |
13 ms |
25112 KB |
Output is correct |
11 |
Correct |
13 ms |
24916 KB |
Output is correct |
12 |
Correct |
13 ms |
24976 KB |
Output is correct |
13 |
Correct |
13 ms |
25020 KB |
Output is correct |
14 |
Correct |
13 ms |
24916 KB |
Output is correct |
15 |
Correct |
13 ms |
25172 KB |
Output is correct |
16 |
Correct |
13 ms |
25172 KB |
Output is correct |
17 |
Correct |
14 ms |
25172 KB |
Output is correct |
18 |
Correct |
13 ms |
25224 KB |
Output is correct |
19 |
Correct |
13 ms |
25568 KB |
Output is correct |
20 |
Correct |
14 ms |
25576 KB |
Output is correct |
21 |
Correct |
13 ms |
25556 KB |
Output is correct |
22 |
Correct |
13 ms |
25528 KB |
Output is correct |
23 |
Correct |
14 ms |
26132 KB |
Output is correct |
24 |
Correct |
16 ms |
26120 KB |
Output is correct |
25 |
Correct |
15 ms |
26132 KB |
Output is correct |
26 |
Correct |
17 ms |
26068 KB |
Output is correct |
27 |
Correct |
14 ms |
27348 KB |
Output is correct |
28 |
Correct |
15 ms |
27284 KB |
Output is correct |
29 |
Correct |
15 ms |
27288 KB |
Output is correct |
30 |
Correct |
16 ms |
27384 KB |
Output is correct |
31 |
Correct |
18 ms |
29652 KB |
Output is correct |
32 |
Correct |
18 ms |
29692 KB |
Output is correct |
33 |
Correct |
19 ms |
29652 KB |
Output is correct |
34 |
Correct |
18 ms |
29652 KB |
Output is correct |
35 |
Correct |
23 ms |
34504 KB |
Output is correct |
36 |
Correct |
23 ms |
34456 KB |
Output is correct |
37 |
Correct |
24 ms |
34404 KB |
Output is correct |
38 |
Correct |
29 ms |
34516 KB |
Output is correct |
39 |
Correct |
34 ms |
43788 KB |
Output is correct |
40 |
Correct |
45 ms |
43900 KB |
Output is correct |
41 |
Correct |
34 ms |
43464 KB |
Output is correct |
42 |
Correct |
35 ms |
43868 KB |
Output is correct |
43 |
Correct |
77 ms |
94880 KB |
Output is correct |
44 |
Correct |
77 ms |
94884 KB |
Output is correct |
45 |
Correct |
78 ms |
94712 KB |
Output is correct |
46 |
Correct |
75 ms |
94696 KB |
Output is correct |
47 |
Correct |
150 ms |
164160 KB |
Output is correct |
48 |
Correct |
141 ms |
164740 KB |
Output is correct |
49 |
Correct |
143 ms |
163888 KB |
Output is correct |
50 |
Correct |
143 ms |
163788 KB |
Output is correct |
51 |
Correct |
276 ms |
303052 KB |
Output is correct |
52 |
Correct |
275 ms |
302120 KB |
Output is correct |
53 |
Correct |
272 ms |
301864 KB |
Output is correct |
54 |
Correct |
288 ms |
302332 KB |
Output is correct |
55 |
Runtime error |
472 ms |
524288 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
24916 KB |
Output is correct |
2 |
Correct |
13 ms |
24952 KB |
Output is correct |
3 |
Correct |
12 ms |
24908 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
13 ms |
24916 KB |
Output is correct |
6 |
Correct |
15 ms |
25004 KB |
Output is correct |
7 |
Correct |
14 ms |
24916 KB |
Output is correct |
8 |
Correct |
13 ms |
24952 KB |
Output is correct |
9 |
Correct |
13 ms |
25084 KB |
Output is correct |
10 |
Correct |
13 ms |
25172 KB |
Output is correct |
11 |
Runtime error |
32 ms |
51472 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
24916 KB |
Output is correct |
2 |
Correct |
12 ms |
24996 KB |
Output is correct |
3 |
Correct |
15 ms |
24916 KB |
Output is correct |
4 |
Correct |
13 ms |
24916 KB |
Output is correct |
5 |
Correct |
12 ms |
24916 KB |
Output is correct |
6 |
Correct |
12 ms |
24900 KB |
Output is correct |
7 |
Correct |
12 ms |
24912 KB |
Output is correct |
8 |
Correct |
14 ms |
24916 KB |
Output is correct |
9 |
Correct |
14 ms |
25172 KB |
Output is correct |
10 |
Correct |
13 ms |
25112 KB |
Output is correct |
11 |
Correct |
13 ms |
24916 KB |
Output is correct |
12 |
Correct |
13 ms |
24976 KB |
Output is correct |
13 |
Correct |
13 ms |
25020 KB |
Output is correct |
14 |
Correct |
13 ms |
24916 KB |
Output is correct |
15 |
Correct |
13 ms |
25172 KB |
Output is correct |
16 |
Correct |
13 ms |
25172 KB |
Output is correct |
17 |
Correct |
14 ms |
25172 KB |
Output is correct |
18 |
Correct |
13 ms |
25224 KB |
Output is correct |
19 |
Correct |
13 ms |
25568 KB |
Output is correct |
20 |
Correct |
14 ms |
25576 KB |
Output is correct |
21 |
Correct |
13 ms |
25556 KB |
Output is correct |
22 |
Correct |
13 ms |
25528 KB |
Output is correct |
23 |
Correct |
14 ms |
26132 KB |
Output is correct |
24 |
Correct |
16 ms |
26120 KB |
Output is correct |
25 |
Correct |
15 ms |
26132 KB |
Output is correct |
26 |
Correct |
17 ms |
26068 KB |
Output is correct |
27 |
Correct |
14 ms |
27348 KB |
Output is correct |
28 |
Correct |
15 ms |
27284 KB |
Output is correct |
29 |
Correct |
15 ms |
27288 KB |
Output is correct |
30 |
Correct |
16 ms |
27384 KB |
Output is correct |
31 |
Correct |
18 ms |
29652 KB |
Output is correct |
32 |
Correct |
18 ms |
29692 KB |
Output is correct |
33 |
Correct |
19 ms |
29652 KB |
Output is correct |
34 |
Correct |
18 ms |
29652 KB |
Output is correct |
35 |
Correct |
23 ms |
34504 KB |
Output is correct |
36 |
Correct |
23 ms |
34456 KB |
Output is correct |
37 |
Correct |
24 ms |
34404 KB |
Output is correct |
38 |
Correct |
29 ms |
34516 KB |
Output is correct |
39 |
Correct |
34 ms |
43788 KB |
Output is correct |
40 |
Correct |
45 ms |
43900 KB |
Output is correct |
41 |
Correct |
34 ms |
43464 KB |
Output is correct |
42 |
Correct |
35 ms |
43868 KB |
Output is correct |
43 |
Correct |
77 ms |
94880 KB |
Output is correct |
44 |
Correct |
77 ms |
94884 KB |
Output is correct |
45 |
Correct |
78 ms |
94712 KB |
Output is correct |
46 |
Correct |
75 ms |
94696 KB |
Output is correct |
47 |
Correct |
150 ms |
164160 KB |
Output is correct |
48 |
Correct |
141 ms |
164740 KB |
Output is correct |
49 |
Correct |
143 ms |
163888 KB |
Output is correct |
50 |
Correct |
143 ms |
163788 KB |
Output is correct |
51 |
Correct |
276 ms |
303052 KB |
Output is correct |
52 |
Correct |
275 ms |
302120 KB |
Output is correct |
53 |
Correct |
272 ms |
301864 KB |
Output is correct |
54 |
Correct |
288 ms |
302332 KB |
Output is correct |
55 |
Runtime error |
472 ms |
524288 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |