# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
618682 | 2022-08-02T06:39:13 Z | drdilyor | Newspapers (CEOI21_newspapers) | C++17 | 0 ms | 0 KB |
#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) { function<pair<int,int>(int,int)> depth = [&](int i, int p)->pair<int,int> { int res = 0, rese = i; for (int e : adj[i]) { if (e != p) { auto [d, v] = depth(e, i); if (d > res) { res = d; rese = v; } } } return {res, rese}; }; auto [_d, d1] = depth(0, -1); auto [_dd, d2] = depth(d1, -1); vector<int> path = {}; function<bool(int)> findD = [&](int i) { if (i == d2) return true; for (int e : adj[i]) { if (path.empty() || e != path.back()) { path.push_back(e); if (findD(e)) return true; path.pop_back(); } } return false; }; findD(d1); for (int i = 0; i < sz(path); i++) { int v = path[i]; for (int e : adj[v]) { if (i && e == path[i-1]) continue; if (i <sz(path)-1 && e == path[i+1]) continue; if (depth(e,-1).first > 2) 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; } /* █████ █████ ███ ████ ▒▒███ ▒▒███ ▒▒▒ ▒▒███ ███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████ ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒ ███ ▒███ ▒▒██████ ▒▒▒▒▒▒ */