답안 #1108733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108733 2024-11-04T21:16:47 Z Pekiban Newspapers (CEOI21_newspapers) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>

using namespace std;
#define pb push_back

const int N = 1e3+5;
vector<int> g[N], b;
void dfs(int s, int e = -1) {
    bool t = 0;
    b.pb(s);
    for (auto u : g[s]) {
        if (u == e) continue;
        if (t && g[u].size() > 1) {
            cout << "NO\n";
            exit(0);
        }
        if (g[u].size() > 1) {
            dfs(u);
            t = 1;
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    if (m >= n) {
        cout << "NO\n";
        exit(0);
    }
    for (int i = 1; i <= n; ++i) {
        if (g[i].size() > 1) {
            bool ok = 1;
            for (auto u : g[i]) {
                if (g[u].size() > 1)    ok = 0;
            }
            if (ok) {
                dfs(i);
                cout << "YES" << '\n';
                if (b.size() & 1) {
                    cout << 2*b.size() << '\n';
                    for (auto x : b)    cout << x << ' ';
                    for (auto x : b)    cout << x << ' ';
                }
                else {
                    cout << 2*b.size() << '\n';
                    for (auto x : b)    cout << x << ' ';
                    reverse(b.begin(), b.end());
                    for (auto x : b)    cout << x << ' ';
                    cout << '\n';
                }
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Unexpected end of file - token expected
2 Halted 0 ms 0 KB -