답안 #618689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618689 2022-08-02T06:42:12 Z drdilyor Newspapers (CEOI21_newspapers) C++17
4 / 100
1 ms 468 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;
}
 
/*
     █████               █████  ███  ████                               
    ▒▒███               ▒▒███  ▒▒▒  ▒▒███                               
  ███████  ████████   ███████  ████  ▒███  █████ ████  ██████  ████████ 
 ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███  ▒███ ▒▒███ ▒███  ███▒▒███▒▒███▒▒███
▒███ ▒███  ▒███ ▒▒▒ ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ 
▒███ ▒███  ▒███     ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███     
▒▒████████ █████    ▒▒████████ █████ █████ ▒▒███████ ▒▒██████  █████    
 ▒▒▒▒▒▒▒▒ ▒▒▒▒▒      ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒███  ▒▒▒▒▒▒  ▒▒▒▒▒     
                                            ███ ▒███                    
                                           ▒▒██████                     
                                            ▒▒▒▒▒▒
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Partially correct 1 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 1 ms 212 KB Failed to provide a successful strategy.
5 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
6 Partially correct 1 ms 212 KB Failed to provide a successful 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 1 ms 212 KB Output is correct
2 Partially correct 0 ms 212 KB Failed to provide a successful strategy.
3 Partially correct 1 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 320 KB Failed to provide a successful strategy.
6 Partially correct 0 ms 212 KB Failed to provide a successful strategy.
7 Partially correct 1 ms 212 KB Failed to provide a successful strategy.
8 Partially correct 1 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 1 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 332 KB Failed to provide a successful strategy.
14 Partially correct 1 ms 328 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 1 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 1 ms 212 KB Failed to provide a successful strategy.
5 Partially correct 1 ms 324 KB Failed to provide a successful strategy.
6 Partially correct 1 ms 212 KB Failed to provide a successful 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 -