Submission #1011387

#TimeUsernameProblemLanguageResultExecution timeMemory
1011387MilosMilutinovicNewspapers (CEOI21_newspapers)C++14
12 / 100
181 ms524288 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> g(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u; --v; g[u].push_back(v); g[v].push_back(u); } const int inf = (int) 1e9; vector<int> dist(1 << n, inf); vector<int> que(1, (1 << n) - 1); dist[que.back()] = 0; vector<pair<int, int>> prv(1 << n, {-1, -1}); for (int b = 0; b < (int) que.size(); b++) { int mask = que[b]; for (int i = 0; i < n; i++) { if (!(mask >> i & 1)) { continue; } int nmask = 0; for (int j = 0; j < n; j++) { if (i == j) { continue; } if (!(mask >> j & 1)) { continue; } for (int v : g[j]) { nmask |= (1 << v); } } if (dist[nmask] > dist[mask] + 1) { dist[nmask] = dist[mask] + 1; prv[nmask] = {mask, i}; que.push_back(nmask); } } } if (dist[0] == inf) { cout << "NO" << '\n'; return 0; } int c = 0; vector<int> res; while (c != (1 << n) - 1) { int nc = prv[c].first; res.push_back(prv[c].second); c = nc; } cout << "YES" << '\n'; cout << (int) res.size() << '\n'; for (int i : res) { cout << i + 1 << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...