Submission #447587

# Submission time Handle Problem Language Result Execution time Memory
447587 2021-07-26T23:34:32 Z Ozy Village (BOI20_village) C++17
50 / 100
101 ms 17344 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ', '

#define MAX 100000

lli n,a,b,M,m,cent;
lli nh[MAX+2],des[MAX+2];
vector<lli> hijos[MAX+2],orden,nuevo,grande;
lli dp[2][MAX+2];

lli Find(lli pos, lli padre,lli mitad) {

    lli grande = -1;
    for(auto h : hijos[pos]) {
        if (padre == h) continue;
        if (nh[h] > mitad) grande = h;
    }

    if (grande == -1) return pos;
    else return Find(grande,pos,mitad);

}

void DFS(lli pos, lli padre) {

    nh[pos] = 1;
    for (auto h : hijos[pos]) {
        if (h == padre) continue;

        //DP

        DFS(h,pos);
        nh[pos] += nh[h];
    }

    lli x = min(nh[pos],n-nh[pos]);
    M += x*2;
}

void agrega(lli pos, lli padre) {
    nuevo.push_back(pos);
    for (auto h : hijos[pos]) if (h != padre) agrega(h,pos);
}

void solve() {

    lli menor,mayor;
    menor = mayor = -1;
    orden.push_back(cent);

    for (auto h : hijos[cent]) {
        nuevo.clear();
        agrega(h,cent);

        if (menor == -1 || nuevo.size() < menor) menor = nuevo.size();
        if (mayor == -1 || nuevo.size() > mayor) {
            swap(nuevo,grande);
            mayor = grande.size();
        }

        if (nuevo.empty()) continue;
        for (auto act : nuevo) orden.push_back(act);
    }

    for (auto act : grande) orden.push_back(act);
    lli cont = 0;

    rep(i,orden.size()-mayor,orden.size()-1) des[orden[i]] = orden[cont++];
    rep(i,0,orden.size()-mayor-1) des[orden[i]] = orden[cont++];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    rep(i,1,n-1) {
        cin >> a >> b;
        hijos[a].push_back(b);
        hijos[b].push_back(a);
    }

    DFS(1,0);
    cent = Find(1,0,n/2);

    solve();

    cout << M << ' ' << M << endl;
    rep(i,1,n) cout << des[i] << ' ';
    cout << "\n";
    rep(i,1,n) cout << des[i] << ' ';

}

Compilation message

Village.cpp: In function 'void solve()':
Village.cpp:61:41: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   61 |         if (menor == -1 || nuevo.size() < menor) menor = nuevo.size();
      |                            ~~~~~~~~~~~~~^~~~~~~
Village.cpp:62:41: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   62 |         if (mayor == -1 || nuevo.size() > mayor) {
      |                            ~~~~~~~~~~~~~^~~~~~~
Village.cpp:4:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for (int i = (a); i <= (b); i++)
      |                                        ^
Village.cpp:74:5: note: in expansion of macro 'rep'
   74 |     rep(i,orden.size()-mayor,orden.size()-1) des[orden[i]] = orden[cont++];
      |     ^~~
Village.cpp:4:40: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
    4 | #define rep(i,a,b) for (int i = (a); i <= (b); i++)
      |                                        ^
Village.cpp:75:5: note: in expansion of macro 'rep'
   75 |     rep(i,0,orden.size()-mayor-1) des[orden[i]] = orden[cont++];
      |     ^~~
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2676 KB Partially correct
2 Partially correct 2 ms 2636 KB Partially correct
3 Correct 2 ms 2636 KB Output is correct
4 Partially correct 2 ms 2592 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 Partially correct 2 ms 2680 KB Partially correct
9 Partially correct 2 ms 2764 KB Partially correct
10 Partially correct 2 ms 2636 KB Partially correct
11 Partially correct 2 ms 2636 KB Partially correct
12 Partially correct 2 ms 2636 KB Partially correct
13 Partially correct 2 ms 2636 KB Partially correct
14 Correct 2 ms 2636 KB Output is correct
15 Partially correct 2 ms 2636 KB Partially correct
16 Partially correct 2 ms 2636 KB Partially correct
17 Partially correct 2 ms 2636 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2676 KB Partially correct
2 Partially correct 2 ms 2636 KB Partially correct
3 Partially correct 2 ms 2636 KB Partially correct
4 Partially correct 2 ms 2764 KB Partially correct
5 Partially correct 2 ms 2764 KB Partially correct
6 Partially correct 2 ms 2684 KB Partially correct
7 Partially correct 2 ms 2764 KB Partially correct
8 Partially correct 3 ms 2712 KB Partially correct
9 Partially correct 3 ms 2764 KB Partially correct
10 Partially correct 2 ms 2764 KB Partially correct
11 Partially correct 2 ms 2764 KB Partially correct
12 Correct 2 ms 2764 KB Output is correct
13 Partially correct 2 ms 2764 KB Partially correct
14 Partially correct 2 ms 2684 KB Partially correct
15 Partially correct 2 ms 2764 KB Partially correct
16 Partially correct 2 ms 2684 KB Partially correct
17 Partially correct 2 ms 2764 KB Partially correct
18 Partially correct 2 ms 2704 KB Partially correct
19 Partially correct 2 ms 2684 KB Partially correct
20 Partially correct 2 ms 2764 KB Partially correct
21 Partially correct 2 ms 2676 KB Partially correct
22 Partially correct 2 ms 2764 KB Partially correct
23 Partially correct 2 ms 2764 KB Partially correct
24 Partially correct 2 ms 2764 KB Partially correct
25 Partially correct 2 ms 2636 KB Partially correct
26 Partially correct 2 ms 2676 KB Partially correct
27 Partially correct 2 ms 2676 KB Partially correct
28 Partially correct 2 ms 2764 KB Partially correct
29 Partially correct 2 ms 2764 KB Partially correct
30 Partially correct 2 ms 2764 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2676 KB Partially correct
2 Partially correct 2 ms 2636 KB Partially correct
3 Correct 2 ms 2636 KB Output is correct
4 Partially correct 2 ms 2592 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 Partially correct 2 ms 2680 KB Partially correct
9 Partially correct 2 ms 2764 KB Partially correct
10 Partially correct 2 ms 2636 KB Partially correct
11 Partially correct 2 ms 2636 KB Partially correct
12 Partially correct 2 ms 2636 KB Partially correct
13 Partially correct 2 ms 2636 KB Partially correct
14 Correct 2 ms 2636 KB Output is correct
15 Partially correct 2 ms 2636 KB Partially correct
16 Partially correct 2 ms 2636 KB Partially correct
17 Partially correct 2 ms 2636 KB Partially correct
18 Partially correct 2 ms 2676 KB Partially correct
19 Partially correct 2 ms 2636 KB Partially correct
20 Partially correct 2 ms 2636 KB Partially correct
21 Partially correct 2 ms 2764 KB Partially correct
22 Partially correct 2 ms 2764 KB Partially correct
23 Partially correct 2 ms 2684 KB Partially correct
24 Partially correct 2 ms 2764 KB Partially correct
25 Partially correct 3 ms 2712 KB Partially correct
26 Partially correct 3 ms 2764 KB Partially correct
27 Partially correct 2 ms 2764 KB Partially correct
28 Partially correct 2 ms 2764 KB Partially correct
29 Correct 2 ms 2764 KB Output is correct
30 Partially correct 2 ms 2764 KB Partially correct
31 Partially correct 2 ms 2684 KB Partially correct
32 Partially correct 2 ms 2764 KB Partially correct
33 Partially correct 2 ms 2684 KB Partially correct
34 Partially correct 2 ms 2764 KB Partially correct
35 Partially correct 2 ms 2704 KB Partially correct
36 Partially correct 2 ms 2684 KB Partially correct
37 Partially correct 2 ms 2764 KB Partially correct
38 Partially correct 2 ms 2676 KB Partially correct
39 Partially correct 2 ms 2764 KB Partially correct
40 Partially correct 2 ms 2764 KB Partially correct
41 Partially correct 2 ms 2764 KB Partially correct
42 Partially correct 2 ms 2636 KB Partially correct
43 Partially correct 2 ms 2676 KB Partially correct
44 Partially correct 2 ms 2676 KB Partially correct
45 Partially correct 2 ms 2764 KB Partially correct
46 Partially correct 2 ms 2764 KB Partially correct
47 Partially correct 2 ms 2764 KB Partially correct
48 Partially correct 68 ms 10980 KB Partially correct
49 Partially correct 85 ms 11492 KB Partially correct
50 Partially correct 98 ms 11684 KB Partially correct
51 Partially correct 54 ms 9800 KB Partially correct
52 Partially correct 77 ms 11456 KB Partially correct
53 Partially correct 65 ms 10792 KB Partially correct
54 Partially correct 39 ms 9856 KB Partially correct
55 Partially correct 93 ms 17344 KB Partially correct
56 Partially correct 101 ms 14744 KB Partially correct
57 Partially correct 84 ms 13628 KB Partially correct
58 Partially correct 82 ms 12856 KB Partially correct
59 Partially correct 79 ms 12092 KB Partially correct
60 Correct 58 ms 11228 KB Output is correct
61 Partially correct 59 ms 11728 KB Partially correct
62 Partially correct 67 ms 12312 KB Partially correct
63 Partially correct 63 ms 11536 KB Partially correct
64 Partially correct 70 ms 11724 KB Partially correct
65 Partially correct 67 ms 12252 KB Partially correct
66 Partially correct 61 ms 11420 KB Partially correct
67 Partially correct 47 ms 9480 KB Partially correct
68 Partially correct 57 ms 10680 KB Partially correct
69 Partially correct 68 ms 12792 KB Partially correct
70 Partially correct 62 ms 11404 KB Partially correct
71 Partially correct 44 ms 9300 KB Partially correct
72 Partially correct 50 ms 10168 KB Partially correct
73 Partially correct 67 ms 12344 KB Partially correct
74 Partially correct 58 ms 11296 KB Partially correct
75 Partially correct 78 ms 12212 KB Partially correct
76 Partially correct 72 ms 11980 KB Partially correct
77 Partially correct 75 ms 12088 KB Partially correct
78 Partially correct 45 ms 8904 KB Partially correct
79 Partially correct 51 ms 9780 KB Partially correct
80 Partially correct 81 ms 12228 KB Partially correct
81 Partially correct 69 ms 11672 KB Partially correct
82 Partially correct 64 ms 11584 KB Partially correct