답안 #520442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520442 2022-01-30T02:32:29 Z KoD Newspapers (CEOI21_newspapers) C++17
0 / 100
356 ms 497208 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, M;
    std::cin >> N >> M;
    vector<vector<int>> graph(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        std::cin >> a >> b;
        a -= 1, b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    if (M != N - 1) {
        std::cout << "NO\n";
        return 0;
    }
    vector<int> adj(1 << N);
    for (int set = 0; set < (1 << N); ++set) {
        for (int i = 0; i < N; ++i) {
            if (set >> i & 1) {
                for (const int j : graph[i]) {
                    adj[set] |= 1 << j;
                }
            }
        }
    }
    vector transit(1 << N, vector<int>(N));
    for (int set = 0; set < (1 << N); ++set) {
        for (int i = 0; i < N; ++i) {
            // set -> adj[set] & ~(1 << i)
            transit[adj[set] & ~(1 << i)][i] = set;
        }
    }
    vector<int> dist(1 << N, -1), last(1 << N, -1);
    std::queue<int> que;
    const auto push = [&](const int u, const int d, const int l) {
        if (dist[u] == -1) {
            dist[u] = d;
            last[u] = l;
            que.push(u);
        }
    };
    push(0, 0, -1);
    while (!que.empty()) {
        const int u = que.front();
        que.pop();
        for (int i = 0; i < N; ++i) {
            push(transit[u][i], dist[u] + 1, i);
        }
    }
    int set = (1 << N) - 1;
    if (dist[set] == -1) {
        std::cout << "NO\n";
        return 0;
    }
    std::cout << "YES\n";
    std::cout << dist[set] << '\n';
    while (set != 0) {
        std::cout << last[set] + 1;
        set = adj[set] & ~(1 << last[set]);
        std::cout << " \n"[set == 0];
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 444 KB Output is correct
23 Incorrect 1 ms 588 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Runtime error 356 ms 497208 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 312 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 444 KB Output is correct
23 Incorrect 1 ms 588 KB Output isn't correct
24 Halted 0 ms 0 KB -