# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258882 |
2020-08-06T16:37:29 Z |
easrui |
Village (BOI20_village) |
C++14 |
|
112 ms |
14072 KB |
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
const int MN = 1e5+5;
const int MOD = 1e9+7;
const int INF = 1e9;
ll sz[MN],N,min_ans,max_ans,cnt;
int pos[MN],ord[MN],vmin[MN],vmax[MN];
vector<int> G[MN];
bool vis[MN],done[MN];
void dfs(int s)
{
vis[s] = 1;
sz[s] = 1;
for(int e:G[s]){
if(vis[e]) continue;
dfs(e);
sz[s] += sz[e];
if(done[e]) continue;
else{
done[s] = 1;
swap(vmin[s],vmin[e]);
min_ans += 2;
}
}
if(s!=1) max_ans += min(sz[s],N-sz[s])*2;
else if(!done[s]){
swap(vmin[s],vmin[G[s][0]]);
min_ans += 2;
}
}
void get(int s, int p)
{
ord[++cnt] = s;
pos[s] = cnt;
for(int e:G[s]){
if(e==p) continue;
get(e,s);
}
}
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> N;
for(int i=1; i<N; i++){
int s,e;
cin >> s >> e;
G[s].push_back(e);
G[e].push_back(s);
}
for(int i=1; i<=N; i++) vmin[i] = i;
dfs(1);
int s = 1, p = 0;
while(1){
bool ch = 0;
for(int e:G[s]){
if(e==p) continue;
if(sz[e]>N/2){
ch = 1;
p = s;
s = e;
break;
}
}
if(!ch) break;
}
ord[0] = s;
pos[s] = 0;
for(int e:G[s]) get(e,s);
for(int i=1; i<=N; i++){
vmax[i] = ord[(pos[i]+N/2)%N];
}
cout << min_ans << ' ' << max_ans << '\n';
for(int i=1; i<=N; i++) cout << vmin[i] << ' ';
cout << '\n';
for(int i=1; i<=N; i++) cout << vmax[i] << ' ';
}
# |
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 |
2 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 |
2816 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 |
2816 KB |
Output is correct |
5 |
Correct |
2 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
4 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
2 ms |
2816 KB |
Output is correct |
10 |
Correct |
3 ms |
2816 KB |
Output is correct |
11 |
Correct |
2 ms |
2816 KB |
Output is correct |
12 |
Correct |
2 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 |
2 ms |
2816 KB |
Output is correct |
16 |
Correct |
2 ms |
2816 KB |
Output is correct |
17 |
Correct |
3 ms |
2816 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 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 |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
2 ms |
2816 KB |
Output is correct |
27 |
Correct |
2 ms |
2688 KB |
Output is correct |
28 |
Correct |
2 ms |
2816 KB |
Output is correct |
29 |
Correct |
2 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 |
2 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 |
2816 KB |
Output is correct |
19 |
Correct |
2 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 |
2 ms |
2816 KB |
Output is correct |
23 |
Correct |
2 ms |
2816 KB |
Output is correct |
24 |
Correct |
4 ms |
2816 KB |
Output is correct |
25 |
Correct |
2 ms |
2816 KB |
Output is correct |
26 |
Correct |
2 ms |
2816 KB |
Output is correct |
27 |
Correct |
3 ms |
2816 KB |
Output is correct |
28 |
Correct |
2 ms |
2816 KB |
Output is correct |
29 |
Correct |
2 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 |
2 ms |
2816 KB |
Output is correct |
33 |
Correct |
2 ms |
2816 KB |
Output is correct |
34 |
Correct |
3 ms |
2816 KB |
Output is correct |
35 |
Correct |
2 ms |
2816 KB |
Output is correct |
36 |
Correct |
2 ms |
2816 KB |
Output is correct |
37 |
Correct |
2 ms |
2816 KB |
Output is correct |
38 |
Correct |
3 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 |
2 ms |
2688 KB |
Output is correct |
43 |
Correct |
2 ms |
2816 KB |
Output is correct |
44 |
Correct |
2 ms |
2688 KB |
Output is correct |
45 |
Correct |
2 ms |
2816 KB |
Output is correct |
46 |
Correct |
2 ms |
2816 KB |
Output is correct |
47 |
Correct |
2 ms |
2816 KB |
Output is correct |
48 |
Correct |
80 ms |
9164 KB |
Output is correct |
49 |
Correct |
73 ms |
9720 KB |
Output is correct |
50 |
Correct |
78 ms |
9720 KB |
Output is correct |
51 |
Correct |
56 ms |
8184 KB |
Output is correct |
52 |
Correct |
78 ms |
9592 KB |
Output is correct |
53 |
Correct |
77 ms |
9080 KB |
Output is correct |
54 |
Correct |
37 ms |
8184 KB |
Output is correct |
55 |
Correct |
100 ms |
14072 KB |
Output is correct |
56 |
Correct |
102 ms |
11772 KB |
Output is correct |
57 |
Correct |
88 ms |
11000 KB |
Output is correct |
58 |
Correct |
112 ms |
10304 KB |
Output is correct |
59 |
Correct |
110 ms |
9880 KB |
Output is correct |
60 |
Correct |
59 ms |
9836 KB |
Output is correct |
61 |
Correct |
62 ms |
9880 KB |
Output is correct |
62 |
Correct |
64 ms |
10104 KB |
Output is correct |
63 |
Correct |
59 ms |
9592 KB |
Output is correct |
64 |
Correct |
82 ms |
10104 KB |
Output is correct |
65 |
Correct |
74 ms |
10104 KB |
Output is correct |
66 |
Correct |
55 ms |
9592 KB |
Output is correct |
67 |
Correct |
43 ms |
8056 KB |
Output is correct |
68 |
Correct |
54 ms |
8952 KB |
Output is correct |
69 |
Correct |
64 ms |
10104 KB |
Output is correct |
70 |
Correct |
59 ms |
9720 KB |
Output is correct |
71 |
Correct |
42 ms |
7928 KB |
Output is correct |
72 |
Correct |
48 ms |
8568 KB |
Output is correct |
73 |
Correct |
63 ms |
10104 KB |
Output is correct |
74 |
Correct |
55 ms |
9464 KB |
Output is correct |
75 |
Correct |
85 ms |
9592 KB |
Output is correct |
76 |
Correct |
69 ms |
9592 KB |
Output is correct |
77 |
Correct |
64 ms |
9848 KB |
Output is correct |
78 |
Correct |
40 ms |
7424 KB |
Output is correct |
79 |
Correct |
49 ms |
8184 KB |
Output is correct |
80 |
Correct |
78 ms |
9592 KB |
Output is correct |
81 |
Correct |
67 ms |
9848 KB |
Output is correct |
82 |
Correct |
75 ms |
9980 KB |
Output is correct |