Submission #408881

# Submission time Handle Problem Language Result Execution time Memory
408881 2021-05-19T18:47:45 Z ScarletS Village (BOI20_village) C++17
50 / 100
100 ms 17740 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+1;
int n, ct, sub[N], eC[N], ans[2][N], cost;
long long tot;
vector<int> e[N], v;

void dfs(int c, int p)
{
    int mx=0;
    sub[c]=1;
    for (int i : e[c])
        if (i!=p)
        {
            dfs(i,c);
            sub[c]+=sub[i];
            tot+=min(sub[i],n-sub[i])*2;
            mx=max(mx,sub[i]);
        }
    if (max(mx,n-sub[c])<=n/2)
        ct=c;
}

void dfsAns(int c, int p)
{
    v.push_back(c);
    for (int i : e[c])
        if (i!=p)
            dfsAns(i,c);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x,y;
    cin>>n;
    for (int i=1;i<n;++i)
    {
        cin>>x>>y;
        e[x].push_back(y);
        e[y].push_back(x);
        ans[0][i]=i;
    }
    ans[0][n]=n;
    stack<int> s;
    for (int i=1;i<=n;++i)
    {
        eC[i]=e[i].size();
        if (eC[i]==1)
            s.push(i);
    }
    while (!s.empty())
    {
        x=s.top();
        s.pop();
        for (int i : e[x])
        {
            if (--eC[i]==1)
                s.push(i);
            if (ans[0][x]!=x)
                continue;
            cost+=2;
            swap(ans[0][x],ans[0][i]);
        }
    }
    for (int i=1;i<=n;++i)
        if (ans[0][i]==i)
        {
            cost+=2;
            swap(ans[0][i],ans[0][e[i][0]]);
        }
    dfs(1,0);
    dfsAns(ct,0);
    cout<<cost<<" "<<tot<<"\n";
    for (int i=0;i<n;++i)
        ans[1][v[i]]=v[(i+n/2)%n];
    for (int j=0;j<2;++j)
    {
        for (int i=1;i<=n;++i)
            cout<<ans[j][i]<<" ";
        cout<<"\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Partially correct 2 ms 2636 KB Partially correct
5 Partially correct 2 ms 2636 KB Partially correct
6 Partially correct 2 ms 2636 KB Partially correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2676 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Partially correct 2 ms 2684 KB Partially correct
11 Partially correct 2 ms 2636 KB Partially correct
12 Partially correct 2 ms 2636 KB Partially correct
13 Correct 2 ms 2672 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2636 KB Partially correct
2 Partially correct 2 ms 2636 KB Partially correct
3 Partially correct 3 ms 2672 KB Partially correct
4 Partially correct 4 ms 2764 KB Partially correct
5 Partially correct 3 ms 2784 KB Partially correct
6 Partially correct 3 ms 2764 KB Partially correct
7 Partially correct 3 ms 2764 KB Partially correct
8 Partially correct 3 ms 2672 KB Partially correct
9 Partially correct 3 ms 2660 KB Partially correct
10 Partially correct 3 ms 2680 KB Partially correct
11 Partially correct 3 ms 2652 KB Partially correct
12 Correct 3 ms 2764 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 3 ms 2764 KB Output is correct
15 Correct 3 ms 2764 KB Output is correct
16 Partially correct 3 ms 2764 KB Partially correct
17 Correct 4 ms 2764 KB Output is correct
18 Correct 3 ms 2764 KB Output is correct
19 Correct 3 ms 2680 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 3 ms 2764 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Partially correct 3 ms 2684 KB Partially correct
24 Partially correct 3 ms 2764 KB Partially correct
25 Partially correct 2 ms 2636 KB Partially correct
26 Partially correct 3 ms 2764 KB Partially correct
27 Partially correct 2 ms 2636 KB Partially correct
28 Partially correct 3 ms 2684 KB Partially correct
29 Correct 3 ms 2764 KB Output is correct
30 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Partially correct 2 ms 2636 KB Partially correct
5 Partially correct 2 ms 2636 KB Partially correct
6 Partially correct 2 ms 2636 KB Partially correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2676 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Partially correct 2 ms 2684 KB Partially correct
11 Partially correct 2 ms 2636 KB Partially correct
12 Partially correct 2 ms 2636 KB Partially correct
13 Correct 2 ms 2672 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Partially correct 2 ms 2636 KB Partially correct
19 Partially correct 2 ms 2636 KB Partially correct
20 Partially correct 3 ms 2672 KB Partially correct
21 Partially correct 4 ms 2764 KB Partially correct
22 Partially correct 3 ms 2784 KB Partially correct
23 Partially correct 3 ms 2764 KB Partially correct
24 Partially correct 3 ms 2764 KB Partially correct
25 Partially correct 3 ms 2672 KB Partially correct
26 Partially correct 3 ms 2660 KB Partially correct
27 Partially correct 3 ms 2680 KB Partially correct
28 Partially correct 3 ms 2652 KB Partially correct
29 Correct 3 ms 2764 KB Output is correct
30 Correct 3 ms 2688 KB Output is correct
31 Correct 3 ms 2764 KB Output is correct
32 Correct 3 ms 2764 KB Output is correct
33 Partially correct 3 ms 2764 KB Partially correct
34 Correct 4 ms 2764 KB Output is correct
35 Correct 3 ms 2764 KB Output is correct
36 Correct 3 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 3 ms 2764 KB Output is correct
39 Correct 3 ms 2764 KB Output is correct
40 Partially correct 3 ms 2684 KB Partially correct
41 Partially correct 3 ms 2764 KB Partially correct
42 Partially correct 2 ms 2636 KB Partially correct
43 Partially correct 3 ms 2764 KB Partially correct
44 Partially correct 2 ms 2636 KB Partially correct
45 Partially correct 3 ms 2684 KB Partially correct
46 Correct 3 ms 2764 KB Output is correct
47 Correct 3 ms 2764 KB Output is correct
48 Partially correct 71 ms 9704 KB Partially correct
49 Partially correct 87 ms 10432 KB Partially correct
50 Partially correct 82 ms 10496 KB Partially correct
51 Partially correct 59 ms 8636 KB Partially correct
52 Partially correct 86 ms 10272 KB Partially correct
53 Partially correct 69 ms 9532 KB Partially correct
54 Partially correct 42 ms 9936 KB Partially correct
55 Partially correct 100 ms 17740 KB Partially correct
56 Partially correct 86 ms 13872 KB Partially correct
57 Partially correct 95 ms 12712 KB Partially correct
58 Partially correct 93 ms 11428 KB Partially correct
59 Partially correct 78 ms 10460 KB Partially correct
60 Correct 63 ms 10984 KB Output is correct
61 Correct 69 ms 10944 KB Output is correct
62 Correct 71 ms 10984 KB Output is correct
63 Correct 66 ms 10516 KB Output is correct
64 Partially correct 73 ms 10848 KB Partially correct
65 Correct 71 ms 10972 KB Output is correct
66 Correct 68 ms 10484 KB Output is correct
67 Correct 47 ms 8772 KB Output is correct
68 Correct 58 ms 9644 KB Output is correct
69 Correct 71 ms 11072 KB Output is correct
70 Correct 68 ms 10500 KB Output is correct
71 Correct 47 ms 8508 KB Output is correct
72 Correct 54 ms 9280 KB Output is correct
73 Correct 71 ms 11072 KB Output is correct
74 Correct 62 ms 10340 KB Output is correct
75 Partially correct 81 ms 10172 KB Partially correct
76 Partially correct 76 ms 10328 KB Partially correct
77 Partially correct 72 ms 10560 KB Partially correct
78 Partially correct 46 ms 7980 KB Partially correct
79 Partially correct 56 ms 8892 KB Partially correct
80 Partially correct 87 ms 10224 KB Partially correct
81 Partially correct 73 ms 10676 KB Partially correct
82 Partially correct 71 ms 10860 KB Partially correct