# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
834264 |
2023-08-22T12:25:20 Z |
jasmin |
Village (BOI20_village) |
C++17 |
|
76 ms |
23480 KB |
//BOI 2020
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dfsbig(int v, int p, vector<vector<int> >& adi, vector<int>& pre, int n, int& ans){
pre.push_back(v);
int s=1;
for(auto u: adi[v]){
if(u==p) continue;
s+=dfsbig(u, v, adi, pre, n, ans);
}
ans += 2*min(s, n-s);
return s;
}
bool dfssmall(int v, int p, vector<vector<int> >& adi, vector<int>& go, int& ans, int n){
vector<int> unmatched;
for(auto u: adi[v]){
if(u==p) continue;
if(dfssmall(u, v, adi, go, ans, n)){
unmatched.push_back(u);
}
}
if(unmatched.empty()){
ans+=2;
return true;
}
unmatched.push_back(v);
int s=unmatched.size();
for(int i=0; i<s; i++){
go[unmatched[i]] = unmatched[(i+1)%s];
}
return false;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int> > adi(n);
for(int i=0; i<n-1; i++){
int a, b;
cin >> a >> b;
a--; b--;
adi[a].push_back(b);
adi[b].push_back(a);
}
int leaf=-1;
for(int i=0; i<n; i++){
if(adi[i].size()==1) leaf=i;
}
int smallest=0;
vector<int> gosmall(n);
dfssmall(adi[leaf][0], -1, adi, gosmall, smallest, n);
vector<int> pre;
int biggest=0;
dfsbig(0, -1, adi, pre, n, biggest);
vector<int> gobig(n);
for(int i=0; i<n; i++){
gobig[pre[i]] = pre[(i+(n+1)/2)%n];
}
cout << smallest << " " << biggest << "\n";
for(int i=0; i<n; i++){
cout << gosmall[i]+1 << " ";
}
cout << "\n";
for(int i=0; i<n; i++){
cout << gobig[i]+1 << " ";
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
46 ms |
9176 KB |
Output is correct |
49 |
Correct |
58 ms |
10036 KB |
Output is correct |
50 |
Correct |
50 ms |
10044 KB |
Output is correct |
51 |
Correct |
37 ms |
7864 KB |
Output is correct |
52 |
Correct |
61 ms |
9964 KB |
Output is correct |
53 |
Correct |
38 ms |
8988 KB |
Output is correct |
54 |
Correct |
27 ms |
11976 KB |
Output is correct |
55 |
Correct |
76 ms |
23480 KB |
Output is correct |
56 |
Correct |
55 ms |
16192 KB |
Output is correct |
57 |
Correct |
55 ms |
13056 KB |
Output is correct |
58 |
Correct |
55 ms |
11584 KB |
Output is correct |
59 |
Correct |
57 ms |
10424 KB |
Output is correct |
60 |
Correct |
36 ms |
10292 KB |
Output is correct |
61 |
Correct |
34 ms |
10168 KB |
Output is correct |
62 |
Correct |
36 ms |
10484 KB |
Output is correct |
63 |
Correct |
35 ms |
9844 KB |
Output is correct |
64 |
Correct |
39 ms |
10416 KB |
Output is correct |
65 |
Correct |
39 ms |
10568 KB |
Output is correct |
66 |
Correct |
37 ms |
9828 KB |
Output is correct |
67 |
Correct |
27 ms |
7680 KB |
Output is correct |
68 |
Correct |
31 ms |
8980 KB |
Output is correct |
69 |
Correct |
41 ms |
10632 KB |
Output is correct |
70 |
Correct |
33 ms |
10004 KB |
Output is correct |
71 |
Correct |
28 ms |
7496 KB |
Output is correct |
72 |
Correct |
27 ms |
8448 KB |
Output is correct |
73 |
Correct |
39 ms |
10660 KB |
Output is correct |
74 |
Correct |
35 ms |
9724 KB |
Output is correct |
75 |
Correct |
47 ms |
10508 KB |
Output is correct |
76 |
Correct |
46 ms |
9924 KB |
Output is correct |
77 |
Correct |
42 ms |
10232 KB |
Output is correct |
78 |
Correct |
28 ms |
6984 KB |
Output is correct |
79 |
Correct |
32 ms |
8016 KB |
Output is correct |
80 |
Correct |
49 ms |
10572 KB |
Output is correct |
81 |
Correct |
38 ms |
10372 KB |
Output is correct |
82 |
Correct |
38 ms |
10124 KB |
Output is correct |