/**
* author: BERNARD B.01
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef B01
#include "deb.h"
#else
#define deb(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
if (m != n - 1) {
cout << "NO" << '\n';
return 0;
}
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
--u; --v;
g[u].push_back(v);
g[v].push_back(u);
}
if (n == 1) {
cout << "YES" << '\n';
cout << 1 << '\n';
cout << 1 << '\n';
return 0;
}
if (n == 2) {
cout << "YES" << '\n';
cout << 2 << '\n';
cout << 1 << '\n';
cout << 1 << '\n';
return 0;
}
vector<int> z;
function<void(int, int)> Dfs = [&](int v, int pr) {
int c = 0;
if (g[v].size() > 1) {
z.push_back(v);
c++;
}
bool bl = false;
for (int u : g[v]) {
if (u == pr) {
continue;
}
Dfs(u, v);
if (g[v].size() > 1 && g[u].size() > 1) {
z.push_back(v);
c++;
} else if (g[v].size() > 1 && g[u].size() == 1) {
bl = true;
}
}
if (bl) {
z.push_back(v);
c++;
}
};
Dfs(0, -1);
cout << "YES" << '\n';
cout << (int) z.size() << '\n';
for (int i = 0; i < (int) z.size(); i++) {
if (i > 0) {
cout << " ";
}
cout << z[i] + 1;
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Partially correct |
1 ms |
212 KB |
Failed to provide a successful strategy. |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Partially correct |
0 ms |
212 KB |
Provide a successful but not optimal strategy. |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Partially correct |
1 ms |
212 KB |
Failed to provide a successful strategy. |
9 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |