# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
896170 |
2023-12-31T23:55:11 Z |
ShaShi |
Village (BOI20_village) |
C++17 |
|
55 ms |
17772 KB |
#include <bits/stdc++.h>
// #define int long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << endl, exit(0);
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)1e5 + 7;
const int MOD = 998244353;
const int INF = (int)1e9 + 7;
int n, m, t, flag, k, u, v, w, ans, ans2, tmp, tmp2, tmp3, tmp4;
int arr[MAXN], arr2[MAXN], par[MAXN], h[MAXN], sz[MAXN], cent;
int arr3[MAXN], arr4[MAXN];
vector<int> adj[MAXN];
bool DFS(int v, int p=-1) {
bool res = 0;
for (int u:adj[v]) {
if (u != p) res |= DFS(u, v);
}
if (res) return 0;
if (v != 1) {
swap(arr[v], arr[p]);
ans++;
return 1;
}
swap(arr[1], arr[adj[1][0]]);
ans++;
return 0;
}
void DFSsz(int v, int p=-1) {
sz[v] = 1;
for (int u:adj[v]) {
if (u == p) continue;
DFSsz(u, v);
sz[v] += sz[u];
}
}
int centroid(int tot, int v, int p=-1) {
for (int u:adj[v]) {
if (u != p && 2*sz[u] > tot) {
return centroid(tot, u, v);
}
}
return v;
}
vector<int> vec;
vector<pii> love;
pii tof;
void DFS2(int v, int p=-1) {
vec.pb(v);
for (int u:adj[v]) {
if (u == p || u == cent) continue;
DFS2(u, v);
}
}
void solve() {
vec.pb(cent);
for (auto u:adj[cent]) {
DFS2(u);
}
// cout << "$" << vec.size() << endl;
for (int i=1; i<=n; i++) {
// cout << "!" << i << " " << ((i-1+n/2)%n) << " " << vec[(i-1+n/2)%n] << endl;
arr3[vec[i-1]] = vec[(i-1+n/2)%n];
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
tof.F = -1;
cin >> n;
for (int i=1; i<n; i++) {
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
// Min
for (int i=1; i<=n; i++) arr[i] = i;
DFS(1);
for (int i=1; i<=n; i++) arr2[arr[i]] = i;
// Max
DFSsz(1);
cent = centroid(n, 1);
DFSsz(cent);
for (int i=1; i<=n; i++) arr3[i] = i;
solve();
// cout << "!" << cent << endl;
for (int i=1; i<=n; i++) if (i != cent) ans2 += sz[i];
for (int i=1; i<=n; i++) arr4[arr3[i]] = i;
cout << 2*ans << " " << 2*ans2 << endl;
for (int i=1; i<=n; i++) cout << arr2[i] << " ";
cout << endl;
for (int i=1; i<=n; i++) cout << arr4[i] << " ";
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4564 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4952 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4696 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4564 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
1 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
1 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4952 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4696 KB |
Output is correct |
32 |
Correct |
1 ms |
4700 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
1 ms |
4700 KB |
Output is correct |
36 |
Correct |
1 ms |
4696 KB |
Output is correct |
37 |
Correct |
1 ms |
4696 KB |
Output is correct |
38 |
Correct |
1 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
1 ms |
4700 KB |
Output is correct |
41 |
Correct |
1 ms |
4700 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
1 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4696 KB |
Output is correct |
45 |
Correct |
1 ms |
4700 KB |
Output is correct |
46 |
Correct |
1 ms |
4700 KB |
Output is correct |
47 |
Correct |
1 ms |
4700 KB |
Output is correct |
48 |
Correct |
44 ms |
9932 KB |
Output is correct |
49 |
Correct |
43 ms |
10448 KB |
Output is correct |
50 |
Correct |
44 ms |
10448 KB |
Output is correct |
51 |
Correct |
38 ms |
9084 KB |
Output is correct |
52 |
Correct |
43 ms |
10220 KB |
Output is correct |
53 |
Correct |
38 ms |
9760 KB |
Output is correct |
54 |
Correct |
27 ms |
10960 KB |
Output is correct |
55 |
Partially correct |
55 ms |
17772 KB |
Partially correct |
56 |
Partially correct |
52 ms |
13768 KB |
Partially correct |
57 |
Correct |
51 ms |
12716 KB |
Output is correct |
58 |
Correct |
48 ms |
11472 KB |
Output is correct |
59 |
Correct |
46 ms |
10440 KB |
Output is correct |
60 |
Correct |
33 ms |
10684 KB |
Output is correct |
61 |
Correct |
40 ms |
10700 KB |
Output is correct |
62 |
Correct |
37 ms |
10700 KB |
Output is correct |
63 |
Correct |
37 ms |
10448 KB |
Output is correct |
64 |
Correct |
41 ms |
10704 KB |
Output is correct |
65 |
Correct |
35 ms |
10888 KB |
Output is correct |
66 |
Correct |
36 ms |
10448 KB |
Output is correct |
67 |
Correct |
26 ms |
9160 KB |
Output is correct |
68 |
Correct |
32 ms |
9776 KB |
Output is correct |
69 |
Correct |
39 ms |
10764 KB |
Output is correct |
70 |
Correct |
34 ms |
10444 KB |
Output is correct |
71 |
Correct |
24 ms |
8916 KB |
Output is correct |
72 |
Correct |
28 ms |
9424 KB |
Output is correct |
73 |
Correct |
35 ms |
10820 KB |
Output is correct |
74 |
Correct |
32 ms |
10388 KB |
Output is correct |
75 |
Correct |
42 ms |
10184 KB |
Output is correct |
76 |
Correct |
49 ms |
10424 KB |
Output is correct |
77 |
Correct |
39 ms |
10448 KB |
Output is correct |
78 |
Correct |
26 ms |
8664 KB |
Output is correct |
79 |
Correct |
30 ms |
9172 KB |
Output is correct |
80 |
Correct |
52 ms |
10168 KB |
Output is correct |
81 |
Correct |
37 ms |
10640 KB |
Output is correct |
82 |
Correct |
36 ms |
10692 KB |
Output is correct |