답안 #600387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600387 2022-07-20T19:38:54 Z MilosMilutinovic Village (BOI20_village) C++14
50 / 100
94 ms 20020 KB
/**
 *    author:  wxhtzdy
 *    created: 20.07.2022 21:10:18
**/

/*
https://codeforces.com/contest/1387/submission/92450554
https://codeforces.com/contest/1387/submission/137586993
*/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<pair<long long, vector<int>>> ans;
  {
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    int cnt = 0;
    function<void(int, int)> Dfs = [&](int v, int pr) {
      for (int u : g[v]) {
        if (u != pr) {
          if (p[u] == u) {
            Dfs(u, v);
            if (p[u] == u) {
              cnt += 2;
              swap(p[v], p[u]);           
            }
          }
        }
      }
    };
    Dfs(0, 0);
    if (p[0] == 0) {
      cnt += 2;
      swap(p[0], p[g[0][0]]);
    }
    ans.emplace_back(cnt, p);  
  }
  {       
    int root;
    vector<int> sz(n); 
    function<void(int, int)> Dfs = [&](int v, int pr) {
      sz[v] = 1;
      int mx = 0;
      for (int u : g[v]) {
        if (u != pr) {
          Dfs(u, v);
          sz[v] += sz[u];
          mx = max(mx, sz[u]);
        }
      }
      if (mx * 2 < n && sz[v] * 2 >= n) {
        root = v;
      }
    };
    Dfs(0, 0);
    long long cnt = 0;
    vector<int> a;
    Dfs = [&](int v, int pr) {
      a.push_back(v);
      sz[v] = 1;
      for (int u : g[v]) {
        if (u != pr) {
          Dfs(u, v);
          sz[v] += sz[u];
          cnt += sz[u] * 2;
        }
      }      
    };
    Dfs(root, root);
    vector<int> b;
    for (int i = 0; i < n; i++) {
      b.push_back(a[(i + n / 2) % n]); 
    }
    ans.emplace_back(cnt, b);
  }
  cout << ans[0].first << " " << ans[1].first << '\n';
  for (int j = 0; j < 2; j++) {
    for (int i = 0; i < n; i++) {
      cout << ans[j].second[i] + 1 << " \n"[i == n - 1];
    }
  }  
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 0 ms 316 KB Partially correct
4 Correct 0 ms 224 KB Output is correct
5 Partially correct 0 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Partially correct 0 ms 212 KB Partially correct
8 Partially correct 0 ms 212 KB Partially correct
9 Partially correct 0 ms 324 KB Partially correct
10 Partially correct 0 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Partially correct 0 ms 212 KB Partially correct
14 Partially correct 0 ms 212 KB Partially correct
15 Correct 0 ms 212 KB Output is correct
16 Partially correct 0 ms 212 KB Partially correct
17 Partially correct 0 ms 212 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 340 KB Partially correct
2 Partially correct 1 ms 340 KB Partially correct
3 Partially correct 1 ms 340 KB Partially correct
4 Partially correct 1 ms 328 KB Partially correct
5 Partially correct 1 ms 340 KB Partially correct
6 Partially correct 2 ms 320 KB Partially correct
7 Partially correct 1 ms 468 KB Partially correct
8 Partially correct 1 ms 340 KB Partially correct
9 Partially correct 1 ms 340 KB Partially correct
10 Partially correct 2 ms 340 KB Partially correct
11 Partially correct 1 ms 340 KB Partially correct
12 Partially correct 1 ms 340 KB Partially correct
13 Partially correct 1 ms 340 KB Partially correct
14 Partially correct 1 ms 324 KB Partially correct
15 Partially correct 1 ms 320 KB Partially correct
16 Partially correct 1 ms 340 KB Partially correct
17 Partially correct 1 ms 340 KB Partially correct
18 Partially correct 1 ms 340 KB Partially correct
19 Partially correct 1 ms 320 KB Partially correct
20 Partially correct 1 ms 320 KB Partially correct
21 Partially correct 1 ms 324 KB Partially correct
22 Partially correct 1 ms 340 KB Partially correct
23 Partially correct 1 ms 340 KB Partially correct
24 Partially correct 2 ms 340 KB Partially correct
25 Partially correct 1 ms 324 KB Partially correct
26 Partially correct 1 ms 340 KB Partially correct
27 Partially correct 1 ms 324 KB Partially correct
28 Partially correct 1 ms 340 KB Partially correct
29 Partially correct 1 ms 340 KB Partially correct
30 Partially correct 1 ms 340 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Partially correct 1 ms 212 KB Partially correct
3 Partially correct 0 ms 316 KB Partially correct
4 Correct 0 ms 224 KB Output is correct
5 Partially correct 0 ms 212 KB Partially correct
6 Partially correct 0 ms 212 KB Partially correct
7 Partially correct 0 ms 212 KB Partially correct
8 Partially correct 0 ms 212 KB Partially correct
9 Partially correct 0 ms 324 KB Partially correct
10 Partially correct 0 ms 212 KB Partially correct
11 Partially correct 0 ms 212 KB Partially correct
12 Partially correct 1 ms 212 KB Partially correct
13 Partially correct 0 ms 212 KB Partially correct
14 Partially correct 0 ms 212 KB Partially correct
15 Correct 0 ms 212 KB Output is correct
16 Partially correct 0 ms 212 KB Partially correct
17 Partially correct 0 ms 212 KB Partially correct
18 Partially correct 1 ms 340 KB Partially correct
19 Partially correct 1 ms 340 KB Partially correct
20 Partially correct 1 ms 340 KB Partially correct
21 Partially correct 1 ms 328 KB Partially correct
22 Partially correct 1 ms 340 KB Partially correct
23 Partially correct 2 ms 320 KB Partially correct
24 Partially correct 1 ms 468 KB Partially correct
25 Partially correct 1 ms 340 KB Partially correct
26 Partially correct 1 ms 340 KB Partially correct
27 Partially correct 2 ms 340 KB Partially correct
28 Partially correct 1 ms 340 KB Partially correct
29 Partially correct 1 ms 340 KB Partially correct
30 Partially correct 1 ms 340 KB Partially correct
31 Partially correct 1 ms 324 KB Partially correct
32 Partially correct 1 ms 320 KB Partially correct
33 Partially correct 1 ms 340 KB Partially correct
34 Partially correct 1 ms 340 KB Partially correct
35 Partially correct 1 ms 340 KB Partially correct
36 Partially correct 1 ms 320 KB Partially correct
37 Partially correct 1 ms 320 KB Partially correct
38 Partially correct 1 ms 324 KB Partially correct
39 Partially correct 1 ms 340 KB Partially correct
40 Partially correct 1 ms 340 KB Partially correct
41 Partially correct 2 ms 340 KB Partially correct
42 Partially correct 1 ms 324 KB Partially correct
43 Partially correct 1 ms 340 KB Partially correct
44 Partially correct 1 ms 324 KB Partially correct
45 Partially correct 1 ms 340 KB Partially correct
46 Partially correct 1 ms 340 KB Partially correct
47 Partially correct 1 ms 340 KB Partially correct
48 Partially correct 70 ms 8656 KB Partially correct
49 Partially correct 69 ms 9504 KB Partially correct
50 Partially correct 71 ms 9556 KB Partially correct
51 Partially correct 45 ms 7356 KB Partially correct
52 Partially correct 62 ms 9472 KB Partially correct
53 Partially correct 58 ms 8496 KB Partially correct
54 Partially correct 35 ms 9764 KB Partially correct
55 Partially correct 94 ms 20020 KB Partially correct
56 Partially correct 81 ms 14372 KB Partially correct
57 Partially correct 81 ms 12736 KB Partially correct
58 Partially correct 71 ms 11128 KB Partially correct
59 Partially correct 77 ms 9616 KB Partially correct
60 Correct 44 ms 9644 KB Output is correct
61 Partially correct 47 ms 9780 KB Partially correct
62 Partially correct 66 ms 9844 KB Partially correct
63 Partially correct 54 ms 9308 KB Partially correct
64 Partially correct 71 ms 9844 KB Partially correct
65 Partially correct 60 ms 9908 KB Partially correct
66 Partially correct 49 ms 9340 KB Partially correct
67 Partially correct 38 ms 7216 KB Partially correct
68 Partially correct 45 ms 8584 KB Partially correct
69 Partially correct 59 ms 9960 KB Partially correct
70 Partially correct 59 ms 9440 KB Partially correct
71 Partially correct 33 ms 6912 KB Partially correct
72 Partially correct 40 ms 7752 KB Partially correct
73 Partially correct 72 ms 10088 KB Partially correct
74 Partially correct 47 ms 9152 KB Partially correct
75 Partially correct 62 ms 9388 KB Partially correct
76 Partially correct 65 ms 9420 KB Partially correct
77 Partially correct 56 ms 9464 KB Partially correct
78 Partially correct 40 ms 6468 KB Partially correct
79 Partially correct 41 ms 7364 KB Partially correct
80 Partially correct 80 ms 9424 KB Partially correct
81 Partially correct 55 ms 9628 KB Partially correct
82 Partially correct 52 ms 9740 KB Partially correct