Submission #964322

# Submission time Handle Problem Language Result Execution time Memory
964322 2024-04-16T16:05:24 Z codefox Village (BOI20_village) C++14
50 / 100
80 ms 20972 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

#define int long long

vector<vector<int>> graph;
vector<int> subsize;
vector<int> subtree;
int cent = -1;
int ds = 0;
int n;

void dfs(int i, int p)
{
    int sum = 0;
    bool b = 1;
    for (int ele:graph[i])
    {
        if (ele == p) continue;
        dfs(ele, i);
        if (subsize[ele]*2>n) b = 0;
        subsize[i] += subsize[ele];
        sum += subsize[ele];
    }
    sum = n-sum-1;
    if (sum*2>n) b=0;
    if (b) cent = i;
    subsize[i]++;
}

void dist(int i, int p, int d)
{
    for (int ele:graph[i])
    {
        if (ele == p) continue;
        dist(ele, i, d+1);
    }
    ds += d;
}

void sub(int i, int p)
{
    subtree.push_back(i);
    for (int ele:graph[i])
    {
        if (ele == p) continue;
        sub(ele, i);
    }
}

bool comp(vector<int> &a, vector<int> &b)
{
    if (a.size() > b.size()) return 1;
    else return 0;
}

int32_t main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

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

    cin >> n;

    graph.assign(n, vector<int>());
    subsize.assign(n, 0);


    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(0, -1);

    int mx = -1;

    dist(cent, -1, 0);
    mx = ds*2;

    vector<vector<int>> subs;
    for (int i = 0; i < graph[cent].size(); i++)
    {
        sub(graph[cent][i], cent);
        subs.push_back(subtree);
        subtree.clear();
    }
    subs.push_back(vector<int>(1, cent));
    sort(subs.begin(), subs.end(), comp);

    cout << 0 << " " << mx << endl;

    vector<int> left;
    vector<int> ini;
    vector<int> part(n, 0);
    for (auto ele:subs)
    {
        for (int e:ele) 
        {
            ini.push_back(e);
            left.push_back(e);
        }
    }
    for (int i = 0; i < subs[0].size(); i++)
    {
        part[ini[i]] = left.back();
        left.pop_back();
    }
    int i = subs[0].size();
    for (int ele:left) 
    {
        part[ini[i]] = ele;
        i++;
    }
    for (int i = 1; i <=n; i++) cout << i << " ";
    cout << endl;
    for (int ele:part) cout << ele+1 << " ";
}

Compilation message

Village.cpp: In function 'int32_t main()':
Village.cpp:91:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (int i = 0; i < graph[cent].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~
Village.cpp:113:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |     for (int i = 0; i < subs[0].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
3 Partially correct 0 ms 348 KB Partially correct
4 Partially correct 1 ms 344 KB Partially correct
5 Partially correct 1 ms 348 KB Partially correct
6 Partially correct 0 ms 348 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 1 ms 348 KB Partially correct
10 Partially correct 1 ms 348 KB Partially correct
11 Partially correct 0 ms 344 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 0 ms 348 KB Partially correct
15 Partially correct 1 ms 348 KB Partially correct
16 Partially correct 0 ms 348 KB Partially correct
17 Partially correct 1 ms 348 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 1 ms 344 KB Partially correct
3 Partially correct 1 ms 348 KB Partially correct
4 Partially correct 1 ms 348 KB Partially correct
5 Partially correct 1 ms 348 KB Partially correct
6 Partially correct 1 ms 348 KB Partially correct
7 Partially correct 1 ms 600 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 1 ms 344 KB Partially correct
10 Partially correct 1 ms 604 KB Partially correct
11 Partially correct 1 ms 604 KB Partially correct
12 Partially correct 1 ms 604 KB Partially correct
13 Partially correct 1 ms 604 KB Partially correct
14 Partially correct 1 ms 600 KB Partially correct
15 Partially correct 1 ms 348 KB Partially correct
16 Partially correct 1 ms 348 KB Partially correct
17 Partially correct 1 ms 348 KB Partially correct
18 Partially correct 1 ms 348 KB Partially correct
19 Partially correct 1 ms 604 KB Partially correct
20 Partially correct 1 ms 600 KB Partially correct
21 Partially correct 1 ms 348 KB Partially correct
22 Partially correct 1 ms 348 KB Partially correct
23 Partially correct 1 ms 348 KB Partially correct
24 Partially correct 1 ms 344 KB Partially correct
25 Partially correct 0 ms 348 KB Partially correct
26 Partially correct 1 ms 348 KB Partially correct
27 Partially correct 1 ms 344 KB Partially correct
28 Partially correct 1 ms 604 KB Partially correct
29 Partially correct 1 ms 348 KB Partially correct
30 Partially correct 1 ms 348 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
3 Partially correct 0 ms 348 KB Partially correct
4 Partially correct 1 ms 344 KB Partially correct
5 Partially correct 1 ms 348 KB Partially correct
6 Partially correct 0 ms 348 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 1 ms 348 KB Partially correct
10 Partially correct 1 ms 348 KB Partially correct
11 Partially correct 0 ms 344 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 344 KB Partially correct
14 Partially correct 0 ms 348 KB Partially correct
15 Partially correct 1 ms 348 KB Partially correct
16 Partially correct 0 ms 348 KB Partially correct
17 Partially correct 1 ms 348 KB Partially correct
18 Partially correct 1 ms 344 KB Partially correct
19 Partially correct 1 ms 344 KB Partially correct
20 Partially correct 1 ms 348 KB Partially correct
21 Partially correct 1 ms 348 KB Partially correct
22 Partially correct 1 ms 348 KB Partially correct
23 Partially correct 1 ms 348 KB Partially correct
24 Partially correct 1 ms 600 KB Partially correct
25 Partially correct 1 ms 348 KB Partially correct
26 Partially correct 1 ms 344 KB Partially correct
27 Partially correct 1 ms 604 KB Partially correct
28 Partially correct 1 ms 604 KB Partially correct
29 Partially correct 1 ms 604 KB Partially correct
30 Partially correct 1 ms 604 KB Partially correct
31 Partially correct 1 ms 600 KB Partially correct
32 Partially correct 1 ms 348 KB Partially correct
33 Partially correct 1 ms 348 KB Partially correct
34 Partially correct 1 ms 348 KB Partially correct
35 Partially correct 1 ms 348 KB Partially correct
36 Partially correct 1 ms 604 KB Partially correct
37 Partially correct 1 ms 600 KB Partially correct
38 Partially correct 1 ms 348 KB Partially correct
39 Partially correct 1 ms 348 KB Partially correct
40 Partially correct 1 ms 348 KB Partially correct
41 Partially correct 1 ms 344 KB Partially correct
42 Partially correct 0 ms 348 KB Partially correct
43 Partially correct 1 ms 348 KB Partially correct
44 Partially correct 1 ms 344 KB Partially correct
45 Partially correct 1 ms 604 KB Partially correct
46 Partially correct 1 ms 348 KB Partially correct
47 Partially correct 1 ms 348 KB Partially correct
48 Partially correct 47 ms 12980 KB Partially correct
49 Partially correct 50 ms 13960 KB Partially correct
50 Partially correct 56 ms 13980 KB Partially correct
51 Partially correct 43 ms 10540 KB Partially correct
52 Partially correct 44 ms 12964 KB Partially correct
53 Partially correct 42 ms 12392 KB Partially correct
54 Partially correct 26 ms 10140 KB Partially correct
55 Partially correct 72 ms 20972 KB Partially correct
56 Partially correct 80 ms 17416 KB Partially correct
57 Partially correct 52 ms 16196 KB Partially correct
58 Partially correct 53 ms 15168 KB Partially correct
59 Partially correct 52 ms 14028 KB Partially correct
60 Partially correct 52 ms 19368 KB Partially correct
61 Partially correct 47 ms 15108 KB Partially correct
62 Partially correct 39 ms 13952 KB Partially correct
63 Partially correct 37 ms 13052 KB Partially correct
64 Partially correct 56 ms 13508 KB Partially correct
65 Partially correct 38 ms 13924 KB Partially correct
66 Partially correct 39 ms 12892 KB Partially correct
67 Partially correct 29 ms 10652 KB Partially correct
68 Partially correct 33 ms 11708 KB Partially correct
69 Partially correct 38 ms 13960 KB Partially correct
70 Partially correct 36 ms 12812 KB Partially correct
71 Partially correct 27 ms 9928 KB Partially correct
72 Partially correct 28 ms 10760 KB Partially correct
73 Partially correct 44 ms 14688 KB Partially correct
74 Partially correct 34 ms 12660 KB Partially correct
75 Partially correct 49 ms 14232 KB Partially correct
76 Partially correct 51 ms 13660 KB Partially correct
77 Partially correct 40 ms 13456 KB Partially correct
78 Partially correct 38 ms 9064 KB Partially correct
79 Partially correct 31 ms 10404 KB Partially correct
80 Partially correct 53 ms 14188 KB Partially correct
81 Partially correct 43 ms 13224 KB Partially correct
82 Partially correct 36 ms 13248 KB Partially correct