Submission #332681

# Submission time Handle Problem Language Result Execution time Memory
332681 2020-12-03T02:51:15 Z izhang05 Village (BOI20_village) C++17
25 / 100
700 ms 12156 KB
#include <bits/stdc++.h>

using namespace std;

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template<class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
void print(T a) {
    for (auto i : a) {
        cout << i << " ";
    }
    cout << "\n";
}

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
//freopen("solution.out", "w", stdout);
    freopen("3.in", "r", stdin);
#endif
}

const int maxn = 1e5 + 1;
vector<int> adj[maxn];
int deg[maxn], pos[maxn];

int main() {
    setIO();
    int n;
    cin >> n;
    int a, b;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        --a, --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        ++deg[a], ++deg[b];
        pos[i] = i;
    }
    pos[n - 1] = n - 1;
    unordered_set<int> leafs;
    for (int i = 0; i < n; ++i) {
        if (deg[i] == 1) {
            leafs.insert(i);
        }
    }
    int sol = 0;
    while (!leafs.empty()) {
        int cur = *leafs.begin();
        leafs.erase(leafs.begin());
        int next = adj[cur][0];
        if (pos[cur] == cur) {
            sol += 2;
            swap(pos[cur], pos[next]);
        }
        if (--deg[next] == 1) {
            leafs.insert(adj[cur][0]);
        }
        adj[next].erase(find(adj[next].begin(), adj[next].end(), cur));
    }
    cout << sol << " " << 1 << "\n";
    vector<int> loc(n);
    for (int i = 0; i < n; ++i) {
        loc[pos[i]] = i;
        assert(pos[i] != i);
    }
    for (int i = 0; i < n - 1; ++i) {
        cout << loc[i] + 1 << " ";
    }
    cout << loc[n - 1] + 1 << "\n";
    for (int i = 0; i < n - 1; ++i) {
        cout << 1 << " ";
    }
    cout << 1 << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2688 KB Partially correct
2 Partially correct 2 ms 2668 KB Partially correct
3 Partially correct 2 ms 2668 KB Partially correct
4 Partially correct 2 ms 2668 KB Partially correct
5 Partially correct 2 ms 2668 KB Partially correct
6 Partially correct 2 ms 2796 KB Partially correct
7 Partially correct 2 ms 2668 KB Partially correct
8 Partially correct 2 ms 2668 KB Partially correct
9 Partially correct 2 ms 2668 KB Partially correct
10 Partially correct 2 ms 2668 KB Partially correct
11 Partially correct 2 ms 2668 KB Partially correct
12 Partially correct 2 ms 2668 KB Partially correct
13 Partially correct 2 ms 2796 KB Partially correct
14 Partially correct 3 ms 2688 KB Partially correct
15 Partially correct 2 ms 2680 KB Partially correct
16 Partially correct 2 ms 2668 KB Partially correct
17 Partially correct 2 ms 2668 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2688 KB Partially correct
2 Partially correct 2 ms 2796 KB Partially correct
3 Partially correct 2 ms 2796 KB Partially correct
4 Partially correct 3 ms 2796 KB Partially correct
5 Partially correct 3 ms 2796 KB Partially correct
6 Partially correct 3 ms 2796 KB Partially correct
7 Partially correct 3 ms 2796 KB Partially correct
8 Partially correct 3 ms 2796 KB Partially correct
9 Partially correct 3 ms 2816 KB Partially correct
10 Partially correct 3 ms 2796 KB Partially correct
11 Partially correct 3 ms 2796 KB Partially correct
12 Partially correct 3 ms 2796 KB Partially correct
13 Partially correct 3 ms 2796 KB Partially correct
14 Partially correct 3 ms 2796 KB Partially correct
15 Partially correct 3 ms 2796 KB Partially correct
16 Partially correct 3 ms 2796 KB Partially correct
17 Partially correct 3 ms 2796 KB Partially correct
18 Partially correct 3 ms 2796 KB Partially correct
19 Partially correct 3 ms 2796 KB Partially correct
20 Partially correct 3 ms 2796 KB Partially correct
21 Partially correct 3 ms 2796 KB Partially correct
22 Partially correct 3 ms 2796 KB Partially correct
23 Partially correct 3 ms 2796 KB Partially correct
24 Partially correct 3 ms 2796 KB Partially correct
25 Partially correct 2 ms 2796 KB Partially correct
26 Partially correct 3 ms 2796 KB Partially correct
27 Partially correct 2 ms 2796 KB Partially correct
28 Partially correct 3 ms 2796 KB Partially correct
29 Partially correct 3 ms 2796 KB Partially correct
30 Partially correct 3 ms 2796 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2688 KB Partially correct
2 Partially correct 2 ms 2668 KB Partially correct
3 Partially correct 2 ms 2668 KB Partially correct
4 Partially correct 2 ms 2668 KB Partially correct
5 Partially correct 2 ms 2668 KB Partially correct
6 Partially correct 2 ms 2796 KB Partially correct
7 Partially correct 2 ms 2668 KB Partially correct
8 Partially correct 2 ms 2668 KB Partially correct
9 Partially correct 2 ms 2668 KB Partially correct
10 Partially correct 2 ms 2668 KB Partially correct
11 Partially correct 2 ms 2668 KB Partially correct
12 Partially correct 2 ms 2668 KB Partially correct
13 Partially correct 2 ms 2796 KB Partially correct
14 Partially correct 3 ms 2688 KB Partially correct
15 Partially correct 2 ms 2680 KB Partially correct
16 Partially correct 2 ms 2668 KB Partially correct
17 Partially correct 2 ms 2668 KB Partially correct
18 Partially correct 2 ms 2688 KB Partially correct
19 Partially correct 2 ms 2796 KB Partially correct
20 Partially correct 2 ms 2796 KB Partially correct
21 Partially correct 3 ms 2796 KB Partially correct
22 Partially correct 3 ms 2796 KB Partially correct
23 Partially correct 3 ms 2796 KB Partially correct
24 Partially correct 3 ms 2796 KB Partially correct
25 Partially correct 3 ms 2796 KB Partially correct
26 Partially correct 3 ms 2816 KB Partially correct
27 Partially correct 3 ms 2796 KB Partially correct
28 Partially correct 3 ms 2796 KB Partially correct
29 Partially correct 3 ms 2796 KB Partially correct
30 Partially correct 3 ms 2796 KB Partially correct
31 Partially correct 3 ms 2796 KB Partially correct
32 Partially correct 3 ms 2796 KB Partially correct
33 Partially correct 3 ms 2796 KB Partially correct
34 Partially correct 3 ms 2796 KB Partially correct
35 Partially correct 3 ms 2796 KB Partially correct
36 Partially correct 3 ms 2796 KB Partially correct
37 Partially correct 3 ms 2796 KB Partially correct
38 Partially correct 3 ms 2796 KB Partially correct
39 Partially correct 3 ms 2796 KB Partially correct
40 Partially correct 3 ms 2796 KB Partially correct
41 Partially correct 3 ms 2796 KB Partially correct
42 Partially correct 2 ms 2796 KB Partially correct
43 Partially correct 3 ms 2796 KB Partially correct
44 Partially correct 2 ms 2796 KB Partially correct
45 Partially correct 3 ms 2796 KB Partially correct
46 Partially correct 3 ms 2796 KB Partially correct
47 Partially correct 3 ms 2796 KB Partially correct
48 Partially correct 91 ms 10232 KB Partially correct
49 Partially correct 109 ms 10872 KB Partially correct
50 Partially correct 106 ms 10872 KB Partially correct
51 Partially correct 78 ms 9208 KB Partially correct
52 Partially correct 104 ms 11000 KB Partially correct
53 Partially correct 93 ms 10104 KB Partially correct
54 Partially correct 39 ms 5868 KB Partially correct
55 Partially correct 94 ms 8940 KB Partially correct
56 Partially correct 103 ms 9708 KB Partially correct
57 Partially correct 107 ms 9976 KB Partially correct
58 Partially correct 108 ms 10104 KB Partially correct
59 Partially correct 101 ms 11000 KB Partially correct
60 Execution timed out 1083 ms 12156 KB Time limit exceeded
61 Halted 0 ms 0 KB -