Submission #897489

# Submission time Handle Problem Language Result Execution time Memory
897489 2024-01-03T08:04:07 Z Neco_arc Village (BOI20_village) C++17
50 / 100
46 ms 20816 KB
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define VietAnh "Village"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7

using namespace std;

const ll mod = 1e9 + 7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll GetRandom(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r)(rng);
}

int n;
vector<int> edges[maxn];
int num[maxn];
int vt[maxn], used[maxn], a[maxn];
int child[maxn], cnt;
ll ans1, ans2;

void DFS(int u, int par)
{
    child[u] = 1, vt[++cnt] = u;
    num[cnt] = u;
    for(int v : edges[u]){
        if(v == par) continue;
        DFS(v, u);

        child[u] += child[v];
        if(!used[v]) {
            used[u] = 1, swap(a[u], a[v]);
            ans2 += 2;
        }
    }

    if(u != 1) ans1 += min(child[u], n - child[u]) * 2;
    else if(!used[1]) ans2 += 2, swap(a[1], a[edges[1][0]]);

}

void solve()
{

    cin >> n;

    fi(i, 1, n - 1) {
        int x, y;
        cin >> x >> y;

        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    fi(i, 1, n) a[i] = i;
    DFS(1, 0);

    fi(i, n + 1, 2 * n) vt[i] = vt[i - n];

    cout << ans2 << " " << ans1 <<'\n';
    fi(i, 1, n) cout << a[i] << " ";
    cout << '\n';
    fi(i, 1, n) cout << vt[num[i] + (n / 2)] << " ";
}


int main()
{

    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(VietAnh".inp", "r")) {
        freopen(VietAnh".inp", "r", stdin);
        freopen(VietAnh".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;

    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

Village.cpp: In function 'int main()':
Village.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(VietAnh".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Village.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(VietAnh".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Partially correct 2 ms 8796 KB Partially correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8792 KB Output is correct
5 Partially correct 2 ms 8792 KB Partially correct
6 Partially correct 2 ms 8796 KB Partially correct
7 Partially correct 2 ms 8796 KB Partially correct
8 Partially correct 1 ms 8796 KB Partially correct
9 Partially correct 2 ms 8796 KB Partially correct
10 Partially correct 2 ms 8796 KB Partially correct
11 Partially correct 1 ms 8796 KB Partially correct
12 Partially correct 2 ms 8792 KB Partially correct
13 Partially correct 1 ms 8796 KB Partially correct
14 Correct 2 ms 8796 KB Output is correct
15 Partially correct 1 ms 8792 KB Partially correct
16 Correct 2 ms 8792 KB Output is correct
17 Partially correct 1 ms 8796 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 8792 KB Partially correct
2 Partially correct 2 ms 8796 KB Partially correct
3 Partially correct 2 ms 8796 KB Partially correct
4 Partially correct 2 ms 8796 KB Partially correct
5 Partially correct 2 ms 8796 KB Partially correct
6 Partially correct 2 ms 8796 KB Partially correct
7 Partially correct 3 ms 9048 KB Partially correct
8 Partially correct 2 ms 8792 KB Partially correct
9 Partially correct 2 ms 8796 KB Partially correct
10 Partially correct 2 ms 8792 KB Partially correct
11 Partially correct 2 ms 8796 KB Partially correct
12 Correct 2 ms 8796 KB Output is correct
13 Partially correct 2 ms 8796 KB Partially correct
14 Partially correct 2 ms 8796 KB Partially correct
15 Partially correct 2 ms 8796 KB Partially correct
16 Partially correct 2 ms 8792 KB Partially correct
17 Partially correct 2 ms 8792 KB Partially correct
18 Partially correct 2 ms 8796 KB Partially correct
19 Partially correct 2 ms 8796 KB Partially correct
20 Partially correct 2 ms 8796 KB Partially correct
21 Partially correct 2 ms 8792 KB Partially correct
22 Partially correct 2 ms 8792 KB Partially correct
23 Partially correct 2 ms 8796 KB Partially correct
24 Partially correct 2 ms 8796 KB Partially correct
25 Partially correct 2 ms 8796 KB Partially correct
26 Partially correct 2 ms 8940 KB Partially correct
27 Partially correct 2 ms 8796 KB Partially correct
28 Partially correct 2 ms 8796 KB Partially correct
29 Partially correct 2 ms 8796 KB Partially correct
30 Partially correct 2 ms 8796 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Partially correct 2 ms 8796 KB Partially correct
3 Correct 1 ms 8796 KB Output is correct
4 Correct 1 ms 8792 KB Output is correct
5 Partially correct 2 ms 8792 KB Partially correct
6 Partially correct 2 ms 8796 KB Partially correct
7 Partially correct 2 ms 8796 KB Partially correct
8 Partially correct 1 ms 8796 KB Partially correct
9 Partially correct 2 ms 8796 KB Partially correct
10 Partially correct 2 ms 8796 KB Partially correct
11 Partially correct 1 ms 8796 KB Partially correct
12 Partially correct 2 ms 8792 KB Partially correct
13 Partially correct 1 ms 8796 KB Partially correct
14 Correct 2 ms 8796 KB Output is correct
15 Partially correct 1 ms 8792 KB Partially correct
16 Correct 2 ms 8792 KB Output is correct
17 Partially correct 1 ms 8796 KB Partially correct
18 Partially correct 2 ms 8792 KB Partially correct
19 Partially correct 2 ms 8796 KB Partially correct
20 Partially correct 2 ms 8796 KB Partially correct
21 Partially correct 2 ms 8796 KB Partially correct
22 Partially correct 2 ms 8796 KB Partially correct
23 Partially correct 2 ms 8796 KB Partially correct
24 Partially correct 3 ms 9048 KB Partially correct
25 Partially correct 2 ms 8792 KB Partially correct
26 Partially correct 2 ms 8796 KB Partially correct
27 Partially correct 2 ms 8792 KB Partially correct
28 Partially correct 2 ms 8796 KB Partially correct
29 Correct 2 ms 8796 KB Output is correct
30 Partially correct 2 ms 8796 KB Partially correct
31 Partially correct 2 ms 8796 KB Partially correct
32 Partially correct 2 ms 8796 KB Partially correct
33 Partially correct 2 ms 8792 KB Partially correct
34 Partially correct 2 ms 8792 KB Partially correct
35 Partially correct 2 ms 8796 KB Partially correct
36 Partially correct 2 ms 8796 KB Partially correct
37 Partially correct 2 ms 8796 KB Partially correct
38 Partially correct 2 ms 8792 KB Partially correct
39 Partially correct 2 ms 8792 KB Partially correct
40 Partially correct 2 ms 8796 KB Partially correct
41 Partially correct 2 ms 8796 KB Partially correct
42 Partially correct 2 ms 8796 KB Partially correct
43 Partially correct 2 ms 8940 KB Partially correct
44 Partially correct 2 ms 8796 KB Partially correct
45 Partially correct 2 ms 8796 KB Partially correct
46 Partially correct 2 ms 8796 KB Partially correct
47 Partially correct 2 ms 8796 KB Partially correct
48 Partially correct 33 ms 12888 KB Partially correct
49 Partially correct 35 ms 13396 KB Partially correct
50 Partially correct 39 ms 13392 KB Partially correct
51 Partially correct 27 ms 12380 KB Partially correct
52 Partially correct 35 ms 13396 KB Partially correct
53 Partially correct 31 ms 12880 KB Partially correct
54 Partially correct 21 ms 14680 KB Partially correct
55 Partially correct 41 ms 20816 KB Partially correct
56 Partially correct 39 ms 16864 KB Partially correct
57 Partially correct 37 ms 15696 KB Partially correct
58 Partially correct 46 ms 14932 KB Partially correct
59 Partially correct 36 ms 13396 KB Partially correct
60 Partially correct 33 ms 13516 KB Partially correct
61 Partially correct 31 ms 13660 KB Partially correct
62 Partially correct 33 ms 13796 KB Partially correct
63 Partially correct 34 ms 13508 KB Partially correct
64 Partially correct 32 ms 13660 KB Partially correct
65 Partially correct 32 ms 13928 KB Partially correct
66 Partially correct 28 ms 13404 KB Partially correct
67 Partially correct 23 ms 12376 KB Partially correct
68 Partially correct 28 ms 13148 KB Partially correct
69 Partially correct 33 ms 13828 KB Partially correct
70 Partially correct 30 ms 13660 KB Partially correct
71 Partially correct 24 ms 12288 KB Partially correct
72 Partially correct 26 ms 12776 KB Partially correct
73 Partially correct 33 ms 13908 KB Partially correct
74 Partially correct 28 ms 13400 KB Partially correct
75 Partially correct 36 ms 13140 KB Partially correct
76 Partially correct 34 ms 13140 KB Partially correct
77 Partially correct 32 ms 13660 KB Partially correct
78 Partially correct 23 ms 11868 KB Partially correct
79 Partially correct 26 ms 12368 KB Partially correct
80 Partially correct 38 ms 13252 KB Partially correct
81 Partially correct 33 ms 13656 KB Partially correct
82 Partially correct 32 ms 13648 KB Partially correct