Submission #618708

#TimeUsernameProblemLanguageResultExecution timeMemory
618708drdilyorNewspapers (CEOI21_newspapers)C++17
4 / 100
314 ms524288 KiB
#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); } if (m != n-1) {cout << "NO\n"; return 0;} bool yes = true; 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,v).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 (stderr)

newspapers.cpp: In function 'int solve()':
newspapers.cpp:5:24: warning: statement has no effect [-Wunused-value]
    5 |     #define debug(...) 42
      |                        ^~
newspapers.cpp:68:5: note: in expansion of macro 'debug'
   68 |     debug(d1, d2, path);
      |     ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...