답안 #520455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520455 2022-01-30T03:47:49 Z KoD Newspapers (CEOI21_newspapers) C++17
16 / 100
730 ms 265164 KB
#include <bits/stdc++.h>

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

vector<int> naive(const vector<vector<int>>& graph) {
    const int N = graph.size();
    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<vector<pair<int, int>>> transit(1 << N);
    for (int set = 0; set < (1 << N); ++set) {
        for (int i = 0; i < N; ++i) {
            transit[adj[set] & ~(1 << i)].emplace_back(set, i);
        }
    }
    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 (const auto& [v, i] : transit[u]) {
            push(v, dist[u] + 1, i);
        }
    }
    int set = (1 << N) - 1;
    if (dist[set] == -1) {
        return {};
    }
    vector<int> ans;
    while (set != 0) {
        ans.push_back(last[set] + 1);
        set = adj[set] & ~(1 << last[set]);
        std::cerr << std::bitset<7>(set) << '\n';
    }
    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, M;
    std::cin >> N >> M;
    if (M != N - 1) {
        std::cout << "NO\n";
        return 0;
    }
    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 (N <= 20) {
        const auto ans = naive(graph);
        const int n = ans.size();
        if (n == 0) {
            std::cout << "NO\n"; 
        } else {
            std::cout << "YES\n" << n << '\n';
            for (int i = 0; i < n; ++i) {
                std::cout << ans[i] << " \n"[i + 1 == n];
            }
        }
    } else {
        std::cout << "YES\n";
        std::cout << "1\n1\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 284 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 472 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 2 ms 972 KB Output is correct
24 Correct 2 ms 972 KB Output is correct
25 Correct 2 ms 972 KB Output is correct
26 Correct 2 ms 972 KB Output is correct
27 Correct 3 ms 1868 KB Output is correct
28 Correct 3 ms 1868 KB Output is correct
29 Correct 3 ms 1868 KB Output is correct
30 Correct 4 ms 1868 KB Output is correct
31 Correct 6 ms 3404 KB Output is correct
32 Correct 7 ms 3320 KB Output is correct
33 Correct 8 ms 3532 KB Output is correct
34 Correct 6 ms 3532 KB Output is correct
35 Correct 14 ms 6696 KB Output is correct
36 Correct 15 ms 7236 KB Output is correct
37 Correct 14 ms 6988 KB Output is correct
38 Correct 16 ms 6860 KB Output is correct
39 Correct 30 ms 14368 KB Output is correct
40 Correct 33 ms 13320 KB Output is correct
41 Correct 26 ms 12900 KB Output is correct
42 Correct 30 ms 14660 KB Output is correct
43 Correct 64 ms 28728 KB Output is correct
44 Correct 54 ms 28620 KB Output is correct
45 Correct 66 ms 28648 KB Output is correct
46 Correct 66 ms 30404 KB Output is correct
47 Correct 122 ms 58472 KB Output is correct
48 Correct 132 ms 59984 KB Output is correct
49 Correct 124 ms 60740 KB Output is correct
50 Correct 135 ms 61540 KB Output is correct
51 Correct 244 ms 117404 KB Output is correct
52 Correct 232 ms 121452 KB Output is correct
53 Correct 256 ms 119600 KB Output is correct
54 Correct 269 ms 116452 KB Output is correct
55 Correct 524 ms 251412 KB Output is correct
56 Correct 501 ms 228544 KB Output is correct
57 Correct 730 ms 265164 KB Output is correct
58 Correct 655 ms 255864 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 0 ms 204 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Partially correct 1 ms 360 KB Failed to provide a successful strategy.
12 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
13 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
14 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
15 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
16 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
17 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
18 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
19 Partially correct 0 ms 332 KB Failed to provide a successful strategy.
20 Partially correct 1 ms 332 KB Failed to provide a successful strategy.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 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 284 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 472 KB Output is correct
19 Correct 2 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 2 ms 972 KB Output is correct
24 Correct 2 ms 972 KB Output is correct
25 Correct 2 ms 972 KB Output is correct
26 Correct 2 ms 972 KB Output is correct
27 Correct 3 ms 1868 KB Output is correct
28 Correct 3 ms 1868 KB Output is correct
29 Correct 3 ms 1868 KB Output is correct
30 Correct 4 ms 1868 KB Output is correct
31 Correct 6 ms 3404 KB Output is correct
32 Correct 7 ms 3320 KB Output is correct
33 Correct 8 ms 3532 KB Output is correct
34 Correct 6 ms 3532 KB Output is correct
35 Correct 14 ms 6696 KB Output is correct
36 Correct 15 ms 7236 KB Output is correct
37 Correct 14 ms 6988 KB Output is correct
38 Correct 16 ms 6860 KB Output is correct
39 Correct 30 ms 14368 KB Output is correct
40 Correct 33 ms 13320 KB Output is correct
41 Correct 26 ms 12900 KB Output is correct
42 Correct 30 ms 14660 KB Output is correct
43 Correct 64 ms 28728 KB Output is correct
44 Correct 54 ms 28620 KB Output is correct
45 Correct 66 ms 28648 KB Output is correct
46 Correct 66 ms 30404 KB Output is correct
47 Correct 122 ms 58472 KB Output is correct
48 Correct 132 ms 59984 KB Output is correct
49 Correct 124 ms 60740 KB Output is correct
50 Correct 135 ms 61540 KB Output is correct
51 Correct 244 ms 117404 KB Output is correct
52 Correct 232 ms 121452 KB Output is correct
53 Correct 256 ms 119600 KB Output is correct
54 Correct 269 ms 116452 KB Output is correct
55 Correct 524 ms 251412 KB Output is correct
56 Correct 501 ms 228544 KB Output is correct
57 Correct 730 ms 265164 KB Output is correct
58 Correct 655 ms 255864 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 0 ms 204 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 0 ms 204 KB Output is correct
68 Correct 0 ms 204 KB Output is correct
69 Correct 0 ms 204 KB Output is correct
70 Correct 0 ms 332 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 1 ms 460 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 1 ms 332 KB Output is correct
76 Correct 1 ms 332 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Incorrect 1 ms 312 KB Output isn't correct
80 Halted 0 ms 0 KB -