This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#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);
}
void win(vi ans){
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);
}
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;
if(dumb == 1){
vi sex;
for1(i, 1, n) if(!used[i]) sex.pb(i);
sex.insert(sex.begin(), 0);
sex.pb(0);
if(sex.size() <= 2) win(sex);
}
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);
win(ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |