Submission #698624

#TimeUsernameProblemLanguageResultExecution timeMemory
698624cig32Newspapers (CEOI21_newspapers)C++17
0 / 100
472 ms524288 KiB
#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); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...