Submission #752581

# Submission time Handle Problem Language Result Execution time Memory
752581 2023-06-03T09:06:15 Z 이동현(#9968) Newspapers (CEOI21_newspapers) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    vector<vector<int>> way(n);
    cin >> n >> m;
    vector<int> deg(n);
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        ++deg[x], ++deg[y];
    }
    if(m != n - 1){
        cout << "NO\n";
        return 0;
    }
    int can = 1;
    int rt = -1, mx = -1;
    for(int i = 0; i < n; ++i){
        if(deg[i] > mx){
            mx = deg[i];
            rt = i;
        }
    }

    int cnt = 0;
    for(auto&nxt:way[rt]){
        cnt += (deg[nxt] > 1);
    }
    if(cnt > 1) can = 0;
    for(int i = 0; i < n; ++i){
        if(i != rt && deg[i] > 2){
            can = 0;
        }
    }

    if(can || (*max_element(deg.begin(), deg.end())) == 2){
        cout << "YES\n1\n1\n";
    }
    else{
        cout << "NO\n";
    }
    
    return 0;
}
# Verdict Execution time Memory 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 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Partially correct 1 ms 212 KB Failed to provide a successful strategy.
3 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -