Submission #255083

# Submission time Handle Problem Language Result Execution time Memory
255083 2020-07-31T08:26:53 Z davitmarg Village (BOI20_village) C++17
100 / 100
96 ms 16756 KB
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 200005;

int n, used[N], vin[N], ans1[N],ans2[N], sz[N], sum1,cnt[N];
LL sum2;
vector<int> g[N],d;

void dfs(int v, int p)
{
    vin[v] = v;
    sz[v] = g[v].size();
    cnt[v] = 1;
    for (int i = 0; i < g[v].size(); i++)
    {
        int to = g[v][i];
        if (to == p)
            continue;
        dfs(to, v);
        sz[v]--;
        cnt[v] += cnt[to];
    }
    d.PB(v);
    sum2 += min(cnt[v], n - cnt[v]);
    if (!used[v] || (v != p && sz[p] == 1 && !used[p]))
    {
        swap(vin[v], vin[p]);
        ans1[vin[p]] = p;
        ans1[vin[v]] = v;
        used[v] = used[p] = 1;
        sum1 += 2;
    }
}

int main()
{
    fastIO;
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, 1);
    for (int i = 0; i < n; i++)
        ans2[d[i]] = d[(i + n / 2) % n];
    cout << sum1 << " " << sum2+sum2 << endl;
    for (int i = 1; i <= n; i++)
        cout << ans1[i] << " ";
    cout << endl;
    for (int i = 1; i <= n; i++)
        cout << ans2[i] << " ";
    cout << endl;

    return 0;
}

/*


*/

Compilation message

Village.cpp: In function 'void dfs(int, int)':
Village.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++)
                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 5120 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 3 ms 5120 KB Output is correct
3 Correct 3 ms 5120 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 5 ms 5120 KB Output is correct
14 Correct 6 ms 5120 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 4 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 3 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 3 ms 5120 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 3 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 3 ms 5120 KB Output is correct
30 Correct 3 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 3 ms 4992 KB Output is correct
7 Correct 3 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 3 ms 5120 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 4 ms 4992 KB Output is correct
13 Correct 3 ms 4992 KB Output is correct
14 Correct 3 ms 4992 KB Output is correct
15 Correct 3 ms 4992 KB Output is correct
16 Correct 3 ms 5120 KB Output is correct
17 Correct 3 ms 4992 KB Output is correct
18 Correct 3 ms 5120 KB Output is correct
19 Correct 3 ms 5120 KB Output is correct
20 Correct 3 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 4 ms 5120 KB Output is correct
25 Correct 4 ms 5120 KB Output is correct
26 Correct 4 ms 5120 KB Output is correct
27 Correct 4 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 4 ms 5120 KB Output is correct
30 Correct 5 ms 5120 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 4 ms 5120 KB Output is correct
37 Correct 3 ms 5120 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 3 ms 5120 KB Output is correct
40 Correct 3 ms 5120 KB Output is correct
41 Correct 3 ms 5120 KB Output is correct
42 Correct 3 ms 5120 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 3 ms 5120 KB Output is correct
45 Correct 4 ms 5120 KB Output is correct
46 Correct 3 ms 5120 KB Output is correct
47 Correct 3 ms 5120 KB Output is correct
48 Correct 63 ms 11760 KB Output is correct
49 Correct 78 ms 12328 KB Output is correct
50 Correct 73 ms 12404 KB Output is correct
51 Correct 52 ms 10864 KB Output is correct
52 Correct 74 ms 12272 KB Output is correct
53 Correct 62 ms 11636 KB Output is correct
54 Correct 37 ms 10872 KB Output is correct
55 Correct 92 ms 16756 KB Output is correct
56 Correct 81 ms 14448 KB Output is correct
57 Correct 79 ms 13680 KB Output is correct
58 Correct 80 ms 13044 KB Output is correct
59 Correct 80 ms 12512 KB Output is correct
60 Correct 62 ms 12656 KB Output is correct
61 Correct 63 ms 12656 KB Output is correct
62 Correct 71 ms 12784 KB Output is correct
63 Correct 56 ms 12284 KB Output is correct
64 Correct 69 ms 12660 KB Output is correct
65 Correct 64 ms 12788 KB Output is correct
66 Correct 60 ms 12276 KB Output is correct
67 Correct 43 ms 10736 KB Output is correct
68 Correct 53 ms 11632 KB Output is correct
69 Correct 62 ms 12912 KB Output is correct
70 Correct 56 ms 12400 KB Output is correct
71 Correct 44 ms 10480 KB Output is correct
72 Correct 50 ms 11252 KB Output is correct
73 Correct 59 ms 12912 KB Output is correct
74 Correct 59 ms 12144 KB Output is correct
75 Correct 81 ms 12400 KB Output is correct
76 Correct 96 ms 12272 KB Output is correct
77 Correct 62 ms 12404 KB Output is correct
78 Correct 46 ms 10100 KB Output is correct
79 Correct 54 ms 10868 KB Output is correct
80 Correct 77 ms 12272 KB Output is correct
81 Correct 76 ms 12532 KB Output is correct
82 Correct 61 ms 12656 KB Output is correct