Submission #718051

#TimeUsernameProblemLanguageResultExecution timeMemory
718051baokhue232005Newspapers (CEOI21_newspapers)C++14
50 / 100
2 ms516 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; vi vc[maxN]; void die(){ cout << "NO\n"; exit(0); } int chi[maxN]; vi steak[maxN]; int used[maxN]; vi ans; void dfs(int node){ used[node] = 1; ans.pb(node); for(int cc : steak[node]){ ans.pb(cc); ans.pb(node); } for(int cc : vc[node]) if(!used[cc]) dfs(cc); } signed main(){ // freopen(".inp", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> z; if(n <= 2){ cout << "YES\n"; cout << n << endl; while(n--) cout << "1 "; cout << endl; exit(0); } if(z >= n) die(); for1(i, 2, n){ cin >> x >> y; vc[x].pb(y); vc[y].pb(x); } for1(i, 1, n) chi[i] = vc[i].size(); memset(used, 0, sizeof(used)); for1(dumb, 0, 1){ vi cac; for1(i, 1, n) steak[i].clear(); for1(i, 1, n) if(!used[i] && chi[i] == 1) cac.pb(i); for(int node : cac) if(chi[node] == 1){ for(int cc : vc[node]) if(!used[cc]){ steak[cc].pb(node); --chi[cc]; used[node] = 1; } } } for1(i, 1, n) if(!used[i] && chi[i] >= 3) die(); for1(i, 1, n) if(!used[i] && chi[i] <= 1){ dfs(i); cout << "YES\n"; if(ans.size() > 1) ans.erase(ans.begin()); if(ans.size() > 1) ans.pop_back(); cout << ans.size() * 2 << endl; for1(dumb, 0, 1){ reverse(all(ans)); for(int cc : ans) cout << cc << " "; } cout << endl; exit(0); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...