Submission #854605

# Submission time Handle Problem Language Result Execution time Memory
854605 2023-09-28T06:49:26 Z gun_gan Village (BOI20_village) C++17
50 / 100
47 ms 28572 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MX = 5e5 + 5;
 
int N;
vector<int> g[MX];

int r, sz[MX], pp[MX], minCost = 0;

void dfs(int v, int p) {
      for(auto u : g[v]) {
            if(u == p) continue;
            dfs(u, v);
            sz[v] += sz[u];
      }
      sz[v]++;

      int lst = 0, z = 0;
      for(auto u : g[v]) {
            if(u == p) continue;
            if(pp[u] == u) {
                  if(lst) {
                        minCost += 4;
                        z = u;
                        swap(pp[u], pp[lst]);
                        lst = 0;
                  } else {
                        lst = u;
                  }
            }
      }

      if(lst) {
            minCost += 2;
            swap(pp[lst], pp[v]);
      } else if(z != 0) {
            swap(pp[z], pp[v]);
      }
}

int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      cin >> N;
      for(int i = 1; i <= N; i++) pp[i] = i;
      for(int i = 0; i < N - 1; i++) {
            int u, v;
            cin >> u >> v;
            g[u].push_back(v);
            g[v].push_back(u);
      }

      r = 0;
      for(int i = 1; i <= N; i++) {
            if(g[i].size() > g[r].size()) r = i;
      }

      dfs(r, 0);

      if(pp[r] == r) {
            swap(pp[r], pp[g[r][0]]);
            minCost += 2;
      }

      for(int i = 1; i <= N; i++) assert(pp[i] != i);

      cout << minCost << " " << 1 << '\n';
      for(int i = 1; i <= N; i++) cout << pp[i] << " ";
      cout << '\n';
      for(int i = 1; i <= N; i++) cout << 1 << " ";
      cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Partially correct 3 ms 15708 KB Partially correct
2 Partially correct 3 ms 15804 KB Partially correct
3 Partially correct 3 ms 15708 KB Partially correct
4 Partially correct 3 ms 15708 KB Partially correct
5 Partially correct 3 ms 15708 KB Partially correct
6 Partially correct 3 ms 15704 KB Partially correct
7 Partially correct 3 ms 15708 KB Partially correct
8 Partially correct 3 ms 15708 KB Partially correct
9 Partially correct 3 ms 15708 KB Partially correct
10 Partially correct 3 ms 15960 KB Partially correct
11 Partially correct 3 ms 15708 KB Partially correct
12 Partially correct 3 ms 15708 KB Partially correct
13 Partially correct 3 ms 15708 KB Partially correct
14 Partially correct 3 ms 15928 KB Partially correct
15 Partially correct 3 ms 15708 KB Partially correct
16 Partially correct 3 ms 15708 KB Partially correct
17 Partially correct 3 ms 15708 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 3 ms 15708 KB Partially correct
2 Partially correct 4 ms 15964 KB Partially correct
3 Partially correct 4 ms 15964 KB Partially correct
4 Partially correct 4 ms 15964 KB Partially correct
5 Partially correct 4 ms 15964 KB Partially correct
6 Partially correct 3 ms 15936 KB Partially correct
7 Partially correct 4 ms 15964 KB Partially correct
8 Partially correct 3 ms 15964 KB Partially correct
9 Partially correct 3 ms 15936 KB Partially correct
10 Partially correct 3 ms 15964 KB Partially correct
11 Partially correct 3 ms 15964 KB Partially correct
12 Partially correct 3 ms 15964 KB Partially correct
13 Partially correct 3 ms 15960 KB Partially correct
14 Partially correct 3 ms 15964 KB Partially correct
15 Partially correct 3 ms 16216 KB Partially correct
16 Partially correct 4 ms 15964 KB Partially correct
17 Partially correct 4 ms 15964 KB Partially correct
18 Partially correct 4 ms 15780 KB Partially correct
19 Partially correct 3 ms 15964 KB Partially correct
20 Partially correct 4 ms 15964 KB Partially correct
21 Partially correct 4 ms 15964 KB Partially correct
22 Partially correct 3 ms 16212 KB Partially correct
23 Partially correct 4 ms 15964 KB Partially correct
24 Partially correct 5 ms 15940 KB Partially correct
25 Partially correct 5 ms 15932 KB Partially correct
26 Partially correct 4 ms 15960 KB Partially correct
27 Partially correct 4 ms 15704 KB Partially correct
28 Partially correct 4 ms 15960 KB Partially correct
29 Partially correct 4 ms 15932 KB Partially correct
30 Partially correct 3 ms 15964 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 3 ms 15708 KB Partially correct
2 Partially correct 3 ms 15804 KB Partially correct
3 Partially correct 3 ms 15708 KB Partially correct
4 Partially correct 3 ms 15708 KB Partially correct
5 Partially correct 3 ms 15708 KB Partially correct
6 Partially correct 3 ms 15704 KB Partially correct
7 Partially correct 3 ms 15708 KB Partially correct
8 Partially correct 3 ms 15708 KB Partially correct
9 Partially correct 3 ms 15708 KB Partially correct
10 Partially correct 3 ms 15960 KB Partially correct
11 Partially correct 3 ms 15708 KB Partially correct
12 Partially correct 3 ms 15708 KB Partially correct
13 Partially correct 3 ms 15708 KB Partially correct
14 Partially correct 3 ms 15928 KB Partially correct
15 Partially correct 3 ms 15708 KB Partially correct
16 Partially correct 3 ms 15708 KB Partially correct
17 Partially correct 3 ms 15708 KB Partially correct
18 Partially correct 3 ms 15708 KB Partially correct
19 Partially correct 4 ms 15964 KB Partially correct
20 Partially correct 4 ms 15964 KB Partially correct
21 Partially correct 4 ms 15964 KB Partially correct
22 Partially correct 4 ms 15964 KB Partially correct
23 Partially correct 3 ms 15936 KB Partially correct
24 Partially correct 4 ms 15964 KB Partially correct
25 Partially correct 3 ms 15964 KB Partially correct
26 Partially correct 3 ms 15936 KB Partially correct
27 Partially correct 3 ms 15964 KB Partially correct
28 Partially correct 3 ms 15964 KB Partially correct
29 Partially correct 3 ms 15964 KB Partially correct
30 Partially correct 3 ms 15960 KB Partially correct
31 Partially correct 3 ms 15964 KB Partially correct
32 Partially correct 3 ms 16216 KB Partially correct
33 Partially correct 4 ms 15964 KB Partially correct
34 Partially correct 4 ms 15964 KB Partially correct
35 Partially correct 4 ms 15780 KB Partially correct
36 Partially correct 3 ms 15964 KB Partially correct
37 Partially correct 4 ms 15964 KB Partially correct
38 Partially correct 4 ms 15964 KB Partially correct
39 Partially correct 3 ms 16212 KB Partially correct
40 Partially correct 4 ms 15964 KB Partially correct
41 Partially correct 5 ms 15940 KB Partially correct
42 Partially correct 5 ms 15932 KB Partially correct
43 Partially correct 4 ms 15960 KB Partially correct
44 Partially correct 4 ms 15704 KB Partially correct
45 Partially correct 4 ms 15960 KB Partially correct
46 Partially correct 4 ms 15932 KB Partially correct
47 Partially correct 3 ms 15964 KB Partially correct
48 Partially correct 36 ms 20816 KB Partially correct
49 Partially correct 41 ms 21072 KB Partially correct
50 Partially correct 46 ms 21180 KB Partially correct
51 Partially correct 32 ms 20056 KB Partially correct
52 Partially correct 41 ms 21180 KB Partially correct
53 Partially correct 38 ms 20724 KB Partially correct
54 Partially correct 25 ms 22140 KB Partially correct
55 Partially correct 46 ms 28572 KB Partially correct
56 Partially correct 44 ms 23892 KB Partially correct
57 Partially correct 47 ms 23384 KB Partially correct
58 Partially correct 46 ms 22064 KB Partially correct
59 Partially correct 40 ms 21356 KB Partially correct
60 Partially correct 34 ms 21452 KB Partially correct
61 Partially correct 38 ms 21476 KB Partially correct
62 Partially correct 37 ms 21468 KB Partially correct
63 Partially correct 36 ms 21328 KB Partially correct
64 Partially correct 38 ms 21584 KB Partially correct
65 Partially correct 46 ms 21564 KB Partially correct
66 Partially correct 33 ms 21332 KB Partially correct
67 Partially correct 30 ms 20056 KB Partially correct
68 Partially correct 34 ms 20788 KB Partially correct
69 Partially correct 40 ms 21588 KB Partially correct
70 Partially correct 34 ms 21328 KB Partially correct
71 Partially correct 29 ms 19804 KB Partially correct
72 Partially correct 30 ms 20512 KB Partially correct
73 Partially correct 36 ms 21588 KB Partially correct
74 Partially correct 34 ms 21080 KB Partially correct
75 Partially correct 43 ms 21076 KB Partially correct
76 Partially correct 39 ms 21076 KB Partially correct
77 Partially correct 37 ms 21328 KB Partially correct
78 Partially correct 27 ms 19460 KB Partially correct
79 Partially correct 29 ms 20048 KB Partially correct
80 Partially correct 38 ms 21076 KB Partially correct
81 Partially correct 41 ms 21568 KB Partially correct
82 Partially correct 39 ms 21316 KB Partially correct