# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
257799 |
2020-08-04T20:11:39 Z |
VEGAnn |
Village (BOI20_village) |
C++14 |
|
122 ms |
15856 KB |
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define i2 array<int,2>
using namespace std;
typedef long long ll;
const int N = 100100;
const int oo = 2e9;
set<i2> setik, oth;
vector<int> g[N], vc;
int n, siz[N], cen, who_kto[N], mrk[N];
ll ans, ANS;
void dfs(int v, int p){
for (int u : g[v]){
if (u == p) continue;
dfs(u, v);
if (mrk[u] < 0){
ANS += 2;
if (mrk[v] < 0){
mrk[v] = u;
mrk[u] = v;
} else {
mrk[u] = mrk[v];
mrk[v] = u;
}
}
}
}
void build_sz(int v, int p){
siz[v] = 1;
for (int u : g[v]){
if (u == p) continue;
build_sz(u, v);
siz[v] += siz[u];
ans += min(siz[u], n - siz[u]);
}
}
int search(int v, int p, int SZ){
for (int u : g[v])
if (u != p && siz[u] > SZ / 2)
return search(u, v, SZ);
return v;
}
void add(int v, int p){
vc.PB(v);
for (int u : g[v]){
if (u == p) continue;
add(u, v);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n;
for (int i = 1; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y);
g[y].PB(x);
}
fill(mrk, mrk + n, -1);
dfs(0, -1);
if (mrk[0] < 0) {
ANS += 2;
mrk[0] = mrk[g[0][0]];
mrk[g[0][0]] = 0;
}
build_sz(0, -1);
cout << ANS << " " << ans * 2 << '\n';
for (int i = 0; i < n; i++)
who_kto[mrk[i]] = i;
for (int i = 0; i < n; i++)
cout << who_kto[i] + 1 << " ";
cout << '\n';
cen = search(0, -1, siz[0]);
for (int u : g[cen])
add(u, cen);
vc.PB(cen);
for (int i = 0; i < n; i++)
who_kto[vc[i]] = vc[(i + n / 2) % n];
for (int i = 0; i < n; i++)
cout << who_kto[i] + 1 << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
3 ms |
2816 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Correct |
2 ms |
2816 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
2 ms |
2816 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
3 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
21 |
Correct |
2 ms |
2816 KB |
Output is correct |
22 |
Correct |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
2 ms |
2816 KB |
Output is correct |
24 |
Correct |
2 ms |
2816 KB |
Output is correct |
25 |
Correct |
3 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2816 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 ms |
2816 KB |
Output is correct |
29 |
Correct |
3 ms |
2816 KB |
Output is correct |
30 |
Correct |
2 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2816 KB |
Output is correct |
22 |
Correct |
3 ms |
2816 KB |
Output is correct |
23 |
Correct |
2 ms |
2816 KB |
Output is correct |
24 |
Correct |
3 ms |
2816 KB |
Output is correct |
25 |
Correct |
2 ms |
2816 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
2 ms |
2816 KB |
Output is correct |
28 |
Correct |
3 ms |
2816 KB |
Output is correct |
29 |
Correct |
3 ms |
2816 KB |
Output is correct |
30 |
Correct |
2 ms |
2816 KB |
Output is correct |
31 |
Correct |
2 ms |
2816 KB |
Output is correct |
32 |
Correct |
3 ms |
2816 KB |
Output is correct |
33 |
Correct |
2 ms |
2816 KB |
Output is correct |
34 |
Correct |
2 ms |
2816 KB |
Output is correct |
35 |
Correct |
2 ms |
2816 KB |
Output is correct |
36 |
Correct |
3 ms |
2816 KB |
Output is correct |
37 |
Correct |
2 ms |
2816 KB |
Output is correct |
38 |
Correct |
2 ms |
2816 KB |
Output is correct |
39 |
Correct |
2 ms |
2816 KB |
Output is correct |
40 |
Correct |
2 ms |
2816 KB |
Output is correct |
41 |
Correct |
2 ms |
2816 KB |
Output is correct |
42 |
Correct |
3 ms |
2688 KB |
Output is correct |
43 |
Correct |
3 ms |
2816 KB |
Output is correct |
44 |
Correct |
2 ms |
2688 KB |
Output is correct |
45 |
Correct |
3 ms |
2816 KB |
Output is correct |
46 |
Correct |
3 ms |
2816 KB |
Output is correct |
47 |
Correct |
2 ms |
2816 KB |
Output is correct |
48 |
Correct |
74 ms |
9416 KB |
Output is correct |
49 |
Correct |
77 ms |
9972 KB |
Output is correct |
50 |
Correct |
97 ms |
10084 KB |
Output is correct |
51 |
Correct |
58 ms |
8420 KB |
Output is correct |
52 |
Correct |
78 ms |
10012 KB |
Output is correct |
53 |
Correct |
78 ms |
9204 KB |
Output is correct |
54 |
Correct |
44 ms |
9184 KB |
Output is correct |
55 |
Correct |
122 ms |
15856 KB |
Output is correct |
56 |
Correct |
120 ms |
12784 KB |
Output is correct |
57 |
Correct |
113 ms |
11760 KB |
Output is correct |
58 |
Correct |
86 ms |
10868 KB |
Output is correct |
59 |
Correct |
76 ms |
10096 KB |
Output is correct |
60 |
Correct |
53 ms |
10224 KB |
Output is correct |
61 |
Correct |
58 ms |
10352 KB |
Output is correct |
62 |
Correct |
62 ms |
10352 KB |
Output is correct |
63 |
Correct |
60 ms |
9980 KB |
Output is correct |
64 |
Correct |
74 ms |
10356 KB |
Output is correct |
65 |
Correct |
69 ms |
10484 KB |
Output is correct |
66 |
Correct |
60 ms |
9972 KB |
Output is correct |
67 |
Correct |
46 ms |
8304 KB |
Output is correct |
68 |
Correct |
58 ms |
9328 KB |
Output is correct |
69 |
Correct |
60 ms |
10480 KB |
Output is correct |
70 |
Correct |
56 ms |
9968 KB |
Output is correct |
71 |
Correct |
40 ms |
8176 KB |
Output is correct |
72 |
Correct |
47 ms |
8820 KB |
Output is correct |
73 |
Correct |
71 ms |
10480 KB |
Output is correct |
74 |
Correct |
74 ms |
9968 KB |
Output is correct |
75 |
Correct |
98 ms |
9840 KB |
Output is correct |
76 |
Correct |
83 ms |
9844 KB |
Output is correct |
77 |
Correct |
80 ms |
10100 KB |
Output is correct |
78 |
Correct |
47 ms |
7668 KB |
Output is correct |
79 |
Correct |
47 ms |
8432 KB |
Output is correct |
80 |
Correct |
81 ms |
9840 KB |
Output is correct |
81 |
Correct |
70 ms |
10228 KB |
Output is correct |
82 |
Correct |
68 ms |
10224 KB |
Output is correct |