# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1033048 |
2024-07-24T12:19:36 Z |
vjudge1 |
Village (BOI20_village) |
C++17 |
|
47 ms |
23744 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ar array
#define ld long double
const int N = 3e5 + 20;
const int K = 200;
const int INF = 1e15;
const int LOG = 24;
const int MOD = 998244353;
vector<int> g[N], ord;
int n, posLo[N], posHi[N], ansLo, ansHi, sz[N];
void dfs(int x,int p){
//cout<<x<<endl;
sz[x] = 1;
ord.push_back(x);
for(auto u: g[x]){
if(u == p)continue;
dfs(u, x);
sz[x] += sz[u];
ansHi += min(sz[u], n - sz[u]);
}
if(posLo[x] == x){
if(p == -1)swap(posLo[x], posLo[g[x][0]]);
else swap(posLo[x], posLo[p]);
ansLo += 2;
}
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n;
for(int i = 1;i < n;i++){
int u, v;
cin>>u>>v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 0;i < n;i++)posLo[i] = i;
dfs(0, -1);
ansHi *= 2;
for(int i = 0;i < n;i++){
//cout<<i<<endl;
int u = ord[i];
int v = ord[(i + n / 2 ) % n];
posHi[u] = v;
}
//assert(0);
cout<<ansLo<<" "<<ansHi<<'\n';
for(int i = 0;i < n;i++)cout<<posLo[i] + 1<<" ";
cout<<'\n';
for(int i = 0;i < n;i++)cout<<posHi[i] + 1<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7512 KB |
Output is correct |
2 |
Correct |
3 ms |
7508 KB |
Output is correct |
3 |
Correct |
3 ms |
7512 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7512 KB |
Output is correct |
6 |
Correct |
3 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7368 KB |
Output is correct |
8 |
Correct |
3 ms |
7516 KB |
Output is correct |
9 |
Correct |
3 ms |
7516 KB |
Output is correct |
10 |
Correct |
3 ms |
7516 KB |
Output is correct |
11 |
Correct |
3 ms |
7516 KB |
Output is correct |
12 |
Correct |
4 ms |
7516 KB |
Output is correct |
13 |
Correct |
3 ms |
7512 KB |
Output is correct |
14 |
Correct |
3 ms |
7516 KB |
Output is correct |
15 |
Correct |
3 ms |
7516 KB |
Output is correct |
16 |
Correct |
4 ms |
7512 KB |
Output is correct |
17 |
Correct |
3 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
5 ms |
7512 KB |
Output is correct |
3 |
Correct |
3 ms |
7516 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
3 ms |
7512 KB |
Output is correct |
6 |
Correct |
3 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7460 KB |
Output is correct |
8 |
Correct |
4 ms |
7436 KB |
Output is correct |
9 |
Correct |
4 ms |
7516 KB |
Output is correct |
10 |
Correct |
3 ms |
7516 KB |
Output is correct |
11 |
Correct |
3 ms |
7516 KB |
Output is correct |
12 |
Correct |
4 ms |
7512 KB |
Output is correct |
13 |
Correct |
3 ms |
7516 KB |
Output is correct |
14 |
Correct |
3 ms |
7516 KB |
Output is correct |
15 |
Correct |
3 ms |
7512 KB |
Output is correct |
16 |
Correct |
3 ms |
7540 KB |
Output is correct |
17 |
Correct |
3 ms |
7516 KB |
Output is correct |
18 |
Correct |
3 ms |
7516 KB |
Output is correct |
19 |
Correct |
3 ms |
7516 KB |
Output is correct |
20 |
Correct |
4 ms |
7512 KB |
Output is correct |
21 |
Correct |
3 ms |
7512 KB |
Output is correct |
22 |
Correct |
3 ms |
7516 KB |
Output is correct |
23 |
Correct |
4 ms |
7516 KB |
Output is correct |
24 |
Correct |
3 ms |
7928 KB |
Output is correct |
25 |
Correct |
3 ms |
7516 KB |
Output is correct |
26 |
Correct |
3 ms |
7516 KB |
Output is correct |
27 |
Correct |
3 ms |
7516 KB |
Output is correct |
28 |
Correct |
4 ms |
7504 KB |
Output is correct |
29 |
Correct |
3 ms |
7512 KB |
Output is correct |
30 |
Correct |
4 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7512 KB |
Output is correct |
2 |
Correct |
3 ms |
7508 KB |
Output is correct |
3 |
Correct |
3 ms |
7512 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7512 KB |
Output is correct |
6 |
Correct |
3 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7368 KB |
Output is correct |
8 |
Correct |
3 ms |
7516 KB |
Output is correct |
9 |
Correct |
3 ms |
7516 KB |
Output is correct |
10 |
Correct |
3 ms |
7516 KB |
Output is correct |
11 |
Correct |
3 ms |
7516 KB |
Output is correct |
12 |
Correct |
4 ms |
7516 KB |
Output is correct |
13 |
Correct |
3 ms |
7512 KB |
Output is correct |
14 |
Correct |
3 ms |
7516 KB |
Output is correct |
15 |
Correct |
3 ms |
7516 KB |
Output is correct |
16 |
Correct |
4 ms |
7512 KB |
Output is correct |
17 |
Correct |
3 ms |
7516 KB |
Output is correct |
18 |
Correct |
3 ms |
7516 KB |
Output is correct |
19 |
Correct |
5 ms |
7512 KB |
Output is correct |
20 |
Correct |
3 ms |
7516 KB |
Output is correct |
21 |
Correct |
3 ms |
7516 KB |
Output is correct |
22 |
Correct |
3 ms |
7512 KB |
Output is correct |
23 |
Correct |
3 ms |
7516 KB |
Output is correct |
24 |
Correct |
3 ms |
7460 KB |
Output is correct |
25 |
Correct |
4 ms |
7436 KB |
Output is correct |
26 |
Correct |
4 ms |
7516 KB |
Output is correct |
27 |
Correct |
3 ms |
7516 KB |
Output is correct |
28 |
Correct |
3 ms |
7516 KB |
Output is correct |
29 |
Correct |
4 ms |
7512 KB |
Output is correct |
30 |
Correct |
3 ms |
7516 KB |
Output is correct |
31 |
Correct |
3 ms |
7516 KB |
Output is correct |
32 |
Correct |
3 ms |
7512 KB |
Output is correct |
33 |
Correct |
3 ms |
7540 KB |
Output is correct |
34 |
Correct |
3 ms |
7516 KB |
Output is correct |
35 |
Correct |
3 ms |
7516 KB |
Output is correct |
36 |
Correct |
3 ms |
7516 KB |
Output is correct |
37 |
Correct |
4 ms |
7512 KB |
Output is correct |
38 |
Correct |
3 ms |
7512 KB |
Output is correct |
39 |
Correct |
3 ms |
7516 KB |
Output is correct |
40 |
Correct |
4 ms |
7516 KB |
Output is correct |
41 |
Correct |
3 ms |
7928 KB |
Output is correct |
42 |
Correct |
3 ms |
7516 KB |
Output is correct |
43 |
Correct |
3 ms |
7516 KB |
Output is correct |
44 |
Correct |
3 ms |
7516 KB |
Output is correct |
45 |
Correct |
4 ms |
7504 KB |
Output is correct |
46 |
Correct |
3 ms |
7512 KB |
Output is correct |
47 |
Correct |
4 ms |
7512 KB |
Output is correct |
48 |
Correct |
37 ms |
15832 KB |
Output is correct |
49 |
Correct |
38 ms |
16640 KB |
Output is correct |
50 |
Correct |
39 ms |
16836 KB |
Output is correct |
51 |
Correct |
30 ms |
14688 KB |
Output is correct |
52 |
Correct |
39 ms |
16580 KB |
Output is correct |
53 |
Correct |
34 ms |
15636 KB |
Output is correct |
54 |
Correct |
29 ms |
15308 KB |
Output is correct |
55 |
Correct |
45 ms |
23744 KB |
Output is correct |
56 |
Correct |
43 ms |
20140 KB |
Output is correct |
57 |
Correct |
47 ms |
18888 KB |
Output is correct |
58 |
Correct |
42 ms |
17864 KB |
Output is correct |
59 |
Correct |
38 ms |
17032 KB |
Output is correct |
60 |
Correct |
32 ms |
16712 KB |
Output is correct |
61 |
Correct |
42 ms |
17008 KB |
Output is correct |
62 |
Correct |
35 ms |
17104 KB |
Output is correct |
63 |
Correct |
34 ms |
16580 KB |
Output is correct |
64 |
Correct |
40 ms |
17096 KB |
Output is correct |
65 |
Correct |
38 ms |
17348 KB |
Output is correct |
66 |
Correct |
36 ms |
16468 KB |
Output is correct |
67 |
Correct |
27 ms |
14540 KB |
Output is correct |
68 |
Correct |
30 ms |
15816 KB |
Output is correct |
69 |
Correct |
38 ms |
17352 KB |
Output is correct |
70 |
Correct |
36 ms |
16584 KB |
Output is correct |
71 |
Correct |
26 ms |
14284 KB |
Output is correct |
72 |
Correct |
30 ms |
15304 KB |
Output is correct |
73 |
Correct |
42 ms |
17360 KB |
Output is correct |
74 |
Correct |
43 ms |
16324 KB |
Output is correct |
75 |
Correct |
40 ms |
17268 KB |
Output is correct |
76 |
Correct |
38 ms |
16580 KB |
Output is correct |
77 |
Correct |
47 ms |
16916 KB |
Output is correct |
78 |
Correct |
26 ms |
13768 KB |
Output is correct |
79 |
Correct |
28 ms |
14804 KB |
Output is correct |
80 |
Correct |
38 ms |
17356 KB |
Output is correct |
81 |
Correct |
35 ms |
17108 KB |
Output is correct |
82 |
Correct |
32 ms |
16844 KB |
Output is correct |