Submission #912827

# Submission time Handle Problem Language Result Execution time Memory
912827 2024-01-20T02:20:49 Z juliany2 Newspapers (CEOI21_newspapers) C++17
0 / 100
1 ms 600 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()

const int N = 1007;
int n, m;
vector<int> adj[N], cur;
int leaf[N];

void dfs(int v) {
    int t = -1;
    for (int u : adj[v]) {
        if (leaf[u])
            leaf[u] = 0;
        else {
            if (t == -1)
                u = t;
            else {
                t = -2;
                break;
            }
        }
    }

    cur.push_back(v);
    leaf[v] = 1;
    if (t > 0)
        dfs(t);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    if (m != n - 1) {
        cout << "NO" << '\n';
        return 0;
    }

    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        fill(leaf + 1, leaf + n + 1, 1);
        cur.clear();

        dfs(i);

        if (accumulate(leaf + 1, leaf + n + 1, 0) == 1) {
            for (int j = 1; j <= n; j++)
                if (leaf[j] == 1)
                    cur.push_back(j);

            if (ans.empty() || cur.size() < ans.size())
                ans = cur;
        }
    }

    if (ans.empty())
        cout << "NO" << '\n';
    else {
        cout << "YES" << '\n' << ans.size() << '\n';
        for (int x : ans)
            cout << x << ' ';
        cout << '\n';
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 348 KB Provide a successful but not optimal strategy.
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 348 KB Provide a successful but not optimal strategy.
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 348 KB Provide a successful but not optimal strategy.
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -