#include <bits/stdc++.h>
using ll = long long;
#define int ll
using namespace std;
#define sz(x) (int)(x).size()
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define mod 998244353
#define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n"
using vi = vector<int>;
using pi = pair<int, int>;
const int N = 1005;
const int inf = 3e18;
int n, m, par[N], used[N], ok[N];
vi adj[N], ret;
pi dfs(int x, int p = -1){
pi res(0, x);
for(auto i : adj[x]){
if(i == p) continue;
par[i] = x;
auto j = dfs(i, x);
j.fi++;
res = max(res, j);
}
return res;
}
void solve(){
cin >> n >> m;
if(n == 1){
cout << "YES\n1\n1"; return;
}
if(n == 2){
cout << "YES\n2\n1 1"; return;
}
if(m != n - 1){
cout << "NO"; return;
}
foru(i, 2, m){
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int o = dfs(1).se;
int z = dfs(o).se;
for(int i = z; ; i = par[i]){
ok[i] = 1;
used[i] = 1;
for(auto j : adj[i]){
ok[j] = 1;
for(auto k : adj[j]) ok[k] = 1;
}
if(i == o) break;
}
for(auto i : ok) if(i == 0){
break;
cout << "NO"; return;
}
for(int i = par[z]; i != o; i = par[i]){
ret.push_back(i);
for(auto j : adj[i]){
if(sz(adj[j]) == 1 or used[j]) continue;
ret.push_back(j);
ret.push_back(i);
}
}
cout << "YES\n" << (sz(ret) << 1) << "\n";
foru(i, 0, sz(ret) - 1) cout << ret[i] << " ";
ford(i, sz(ret) - 1, 0) cout << ret[i] << " ";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1; // cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Partially correct |
0 ms |
340 KB |
Failed to provide a successful strategy. |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
340 KB |
Integer parameter [name=k] equals to 0, violates the range [1, 15] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Partially correct |
0 ms |
340 KB |
Failed to provide a successful strategy. |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |