Submission #717776

#TimeUsernameProblemLanguageResultExecution timeMemory
717776baokhue232005Newspapers (CEOI21_newspapers)C++14
6 / 100
1 ms468 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ // lethal option #include<bits/stdc++.h> using namespace std; #define all(flg) flg.begin(), flg.end() #define int long long #define pb push_back #define fi first #define se second #define endl "\n" #define eb emplace_back #define ii pair<int, int> #define vi vector<int> #define PI 3.141592653589793238462643383279502884 #define ll long long #define ld long double #define for1(i, ff, gg) for(int i = ff; i <= gg; ++i) #define for2(i, ff, gg) for(int i = ff; i >= gg; --i) const ll mod = 1e9 + 7; const int maxN = 1005; const ll oo = 1e18 + 7; int n, a[maxN]; int x, y, z, k; void die(){ cout << "NO\n"; exit(0); } void real_win(vi cac){ vi seap = cac; if(cac.size() % 2 == 0) cac.pb(1); for(int cc : seap) cac.pb(cc); cout << "YES\n"; cout << cac.size() << endl; for(int cc : cac) cout << cc << " "; cout << endl; exit(0); } vi best; int cnt_best = oo; void win(vi cac){ if(cac.size() < cnt_best){ best = cac; cnt_best = cac.size(); } } int sub[maxN]; vi vc[maxN]; void dfs_sub(int node, int par){ sub[node] = 1; for(int cc : vc[node]) if(cc != par){ dfs_sub(cc, node); sub[node] += sub[cc]; } } void solve(int root){ dfs_sub(root, 0); while(1){ bool saved = 0; for(int cc : vc[root]){ if(sub[cc] < sub[root] && sub[cc] > 1){ root = cc; saved = 1; break; } } if(!saved) break; } dfs_sub(root, 0); vi ans; ans.pb(root); while(1){ if(vc[root].empty()) break; int node = vc[root].back(); vc[root].pop_back(); if(sub[node] > sub[root] || sub[node] == 1) continue; if(vc[root].empty()){ root = node; ans.pb(node); continue; } // actual child; spare node inside if(sub[node] > 2) swap(node, vc[root][0]); if(sub[node] <= 2){ ans.pb(node); ans.pb(root); continue; } return; } win(ans); } signed main(){ // freopen(".inp", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> z; if(z >= n) die(); if(n == 1){ cout << "YES\n1\n1\n"; exit(0); } for1(i, 2, n){ cin >> x >> y; vc[x].pb(y); vc[y].pb(x); } solve(1); if(cnt_best != oo) real_win(best); die(); }

Compilation message (stderr)

newspapers.cpp: In function 'void win(std::vector<long long int>)':
newspapers.cpp:50:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   50 |     if(cac.size() < cnt_best){
      |        ~~~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...