#include <bits/stdc++.h>
#ifdef ONPC
#include "t_debug.cpp"
#else
#define debug(...) 42
#endif
#define sz(a) ((int)(a).size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll INFL = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
const int N = 2e5, LOGN = 17, MOD = 1e9+7;
int solve() {
int n;
if (!(cin >> n)) {
return 1;
}
int m; cin >> m;
vector<vector<int>> adj(n);
for (int i = 0;i < m; i++) {
int u, v;
cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
bool yes = n == m + 1;
if (yes) {
vector<int> bad(n);
function<pair<int,int>(int,int)> depth = [&](int i, int p)->pair<int,int> {
if (bad[i]) return {0,-1};
int res = 0, rese = i;
for (int e : adj[i]) {
if (e != p) {
auto [d, v] = depth(e, i);
if (d+1 > res) {
res = d+1;
rese = v;
}
}
}
return {res, rese};
};
auto [_d, d1] = depth(0, -1);
auto [_dd, d2] = depth(d1, -1);
vector<int> path = {d1};
function<bool(int)> findD = [&](int i) {
if (i == d2) return true;
for (int e : adj[i]) {
if (e != path.back()) {
path.push_back(e);
if (findD(e)) return true;
path.pop_back();
}
}
return false;
};
findD(d1);
debug(d1, d2, path);
for (int i : path) bad[i] = true;
for (int i = 0; i < sz(path); i++) {
int v = path[i];
for (int e : adj[v]) {
if (depth(e,-1).first > 1) yes = false;
}
}
}
cout << (yes ? "YES" : "NO") << '\n';
if (yes) {
cout << n << '\n';
for (int i = 1; i <= n; i++) cout << i << ' ';
}
return 0;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
#ifdef ONPC
t = 10000;
#endif
while (t-- && cin) {
if (solve()) break;
#ifdef ONPC
cout << "____________________" << endl;
#endif
}
return 0;
}
/*
█████ █████ ███ ████
▒▒███ ▒▒███ ▒▒▒ ▒▒███
███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████
███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███
▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒
▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███
▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████
▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒
███ ▒███
▒▒██████
▒▒▒▒▒▒
*/
Compilation message
newspapers.cpp: In function 'int solve()':
newspapers.cpp:5:24: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 42
| ^~
newspapers.cpp:69:5: note: in expansion of macro 'debug'
69 | debug(d1, d2, path);
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
3 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
5 |
Runtime error |
290 ms |
524288 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
3 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
5 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
6 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
7 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
8 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
9 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
10 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
11 |
Partially correct |
1 ms |
468 KB |
Failed to provide a successful strategy. |
12 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
13 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
14 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
15 |
Partially correct |
1 ms |
340 KB |
Failed to provide a successful strategy. |
16 |
Partially correct |
1 ms |
468 KB |
Failed to provide a successful strategy. |
17 |
Partially correct |
1 ms |
468 KB |
Failed to provide a successful strategy. |
18 |
Partially correct |
1 ms |
468 KB |
Failed to provide a successful strategy. |
19 |
Partially correct |
1 ms |
468 KB |
Failed to provide a successful strategy. |
20 |
Partially correct |
1 ms |
468 KB |
Failed to provide a successful strategy. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
3 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
4 |
Partially correct |
0 ms |
212 KB |
Failed to provide a successful strategy. |
5 |
Runtime error |
290 ms |
524288 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |