Submission #497187

#TimeUsernameProblemLanguageResultExecution timeMemory
497187VictorNewspapers (CEOI21_newspapers)C++17
4 / 100
7 ms416 KiB
// #pragma GCC target ("avx,avx2,fma") // #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast // #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define per(i, a, b) for (int i = (b - 1); i >= (a); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) x.size() #define pb push_back #define debug(x) cout << #x << " = " << x << endl #define umap unordered_map #define uset unordered_set typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const int INF = 1'000'000'007; int n, m; vi ans, graph[1001]; int parity[1001], cnt[1001]; bitset<1001> removed; void dfs(int u, int p, int c) { parity[u] = c; trav(v, graph[u]) if (v != p) dfs(v, u, c ^ 1); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); memset(parity, -1, sizeof(parity)); cin >> n >> m; if(m>=n){ cout<<"NO"<<endl; return 0; } rep(i, 0, m) { int u, v; cin >> u >> v; graph[--u].pb(--v); graph[v].pb(u); } dfs(0, 0, 0); bool moves = 0; while (1) { if (sz(ans) > 5 * n) break; int need = 0, node; bool stop=1; memset(cnt, 0, sizeof(cnt)); rep(u, 0, n) if (moves == parity[u] && !removed[u]) { stop=0; bool adj_rem = 0; trav(v, graph[u]) { ++cnt[v]; if (removed[v]) adj_rem = 1; } need += adj_rem; if (need) node = u; } if(stop)break; if (need > 1) { cout << "YES" << endl; return 0; } if (!need) { int mx_rem = -1; rep(u, 0, n) if (moves == parity[u] && !removed[u]) { int cur_rem = 0; trav(v, graph[u]) if (cnt[v] == 1)++ cur_rem; if (cur_rem > mx_rem) { mx_rem = cur_rem; node = u; } } } //cout<<"moves = "<<moves<<" node = "<<node<<endl; ans.pb(node); trav(v, graph[node])-- cnt[v]; moves ^= 1; rep(u, 0, n) if (parity[u] == moves && !cnt[u]) removed[u] = 1; } if (sz(ans) > 5 * n) cout << "NO" << endl; else { cout << "YES\n" << 2 * sz(ans) + 1 - moves<<endl; trav(pos,ans)cout<<pos+1<<' '; if(!moves)cout<<"1 "; trav(pos,ans)cout<<pos+1<<' '; cout<<endl; } return 0; }

Compilation message (stderr)

newspapers.cpp: In function 'int main()':
newspapers.cpp:64:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |             if (sz(ans) > 5 * n) break;
      |                         ^
newspapers.cpp:106:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |         if (sz(ans) > 5 * n)
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...