/*
#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 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);
}
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]) 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();
for1(i, 2, n){
cin >> x >> y;
vc[x].pb(y);
vc[y].pb(x);
}
solve(1);
solve(vc[1][0]);
die();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
2 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
3 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
2 |
Partially correct |
1 ms |
344 KB |
Provide a successful but not optimal strategy. |
3 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
7 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
8 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
9 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
10 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
11 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
12 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
13 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
14 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
15 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
16 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
17 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
18 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
19 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
20 |
Partially correct |
1 ms |
468 KB |
Provide a successful but not optimal strategy. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
2 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
3 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
4 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
5 |
Partially correct |
1 ms |
348 KB |
Provide a successful but not optimal strategy. |
6 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Partially correct |
1 ms |
340 KB |
Provide a successful but not optimal strategy. |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |