답안 #723533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723533 2023-04-14T04:04:37 Z t6twotwo Village (BOI20_village) C++17
0 / 100
1 ms 320 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int x; cin >> x; x--;
        int y; cin >> y; y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vector<int> a(n);
    iota(a.begin(), a.end(), 0);
    int ans = 0;
    auto dfs = [&](auto dfs, int x, int p) -> bool {
        vector<int> b;
        for (int y : adj[x]) {
            if (y != p) {
                if (dfs(dfs, y, x)) {
                    b.push_back(y);
                }
            }
        }
        if (b.empty()) {
            return 1;
        }
        ans += b.size() * 2;
        if (b.size() % 2 == 1) {
            swap(a[x], a[b[0]]);
            for (int i = 1; i < b.size(); i++) {
                swap(a[b[i]], a[b[i + 1]]);
            }
        } else {
            swap(a[x], a[b[0]]);
            swap(a[x], a[b[1]]);
            for (int i = 2; i < b.size(); i++) {
                swap(a[b[i]], a[b[i + 1]]);
            }
        }
        return 0;
    };
    if (dfs(dfs, 0, -1)) {
        swap(a[0], a[adj[0][0]]);
        ans += 2;
    }
    cout << ans << " " << 0 << "\n";
    for (int i = 0; i < n; i++) {
        cout << a[i] + 1 << " \n"[i == n - 1];
    }
    for (int i = 0; i < n; i++) {
        cout << 1 << " \n"[i == n - 1];
    }
    return 6/22;
}

Compilation message

Village.cpp: In lambda function:
Village.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int i = 1; i < b.size(); i++) {
      |                             ~~^~~~~~~~~~
Village.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int i = 2; i < b.size(); i++) {
      |                             ~~^~~~~~~~~~
Village.cpp: In instantiation of 'main()::<lambda(auto:23, int, int)> [with auto:23 = main()::<lambda(auto:23, int, int)>]':
Village.cpp:45:23:   required from here
Village.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int i = 1; i < b.size(); i++) {
      |                             ~~^~~~~~~~~~
Village.cpp:39:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             for (int i = 2; i < b.size(); i++) {
      |                             ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 1 ms 316 KB Partially correct
4 Partially correct 1 ms 212 KB Partially correct
5 Partially correct 1 ms 212 KB Partially correct
6 Partially correct 1 ms 212 KB Partially correct
7 Partially correct 0 ms 320 KB Partially correct
8 Partially correct 1 ms 212 KB Partially correct
9 Incorrect 1 ms 224 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 1 ms 316 KB Partially correct
4 Partially correct 1 ms 212 KB Partially correct
5 Partially correct 1 ms 212 KB Partially correct
6 Partially correct 1 ms 212 KB Partially correct
7 Partially correct 0 ms 320 KB Partially correct
8 Partially correct 1 ms 212 KB Partially correct
9 Incorrect 1 ms 224 KB Output isn't correct
10 Halted 0 ms 0 KB -