# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
896173 |
2024-01-01T00:12:09 Z |
ShaShi |
Village (BOI20_village) |
C++17 |
|
56 ms |
21968 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)2e5 + 7;
const int MOD = 998244353;
const int INF = (int)1e9 + 7;
int n, m, t, flag, k, u, v, w, tmp, tmp2, tmp3, tmp4;
int arr[MAXN], arr2[MAXN], par[MAXN], h[MAXN], sz[MAXN], cent;
ll ans, ans2;
int arr3[MAXN], arr4[MAXN];
vector<int> adj[MAXN];
vector<int> vec;
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;
}
void DFS2(int v, int p=-1) {
vec.pb(v);
for (int u:adj[v]) {
if (u != p) DFS2(u, v);
}
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
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);
DFS2(cent);
for (int i=0; i<n; i++) arr3[vec[i]] = vec[(i+(n/2))%n];
for (int i=1; i<=n; i++) if (i != cent) ans2 += sz[i];
cout << 2*ans << " " << ans2*2 << endl;
for (int i=1; i<=n; i++) cout << arr2[i] << " ";
cout << endl;
for (int i=1; i<=n; i++) cout << arr3[i] << " ";
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6756 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6804 KB |
Output is correct |
6 |
Correct |
3 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
3 ms |
6744 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
1 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
1 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
3 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
7000 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
1 ms |
6748 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
1 ms |
6748 KB |
Output is correct |
18 |
Correct |
1 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6756 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6804 KB |
Output is correct |
23 |
Correct |
3 ms |
6744 KB |
Output is correct |
24 |
Correct |
2 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
2 ms |
6748 KB |
Output is correct |
36 |
Correct |
3 ms |
6744 KB |
Output is correct |
37 |
Correct |
2 ms |
6748 KB |
Output is correct |
38 |
Correct |
2 ms |
6748 KB |
Output is correct |
39 |
Correct |
2 ms |
6748 KB |
Output is correct |
40 |
Correct |
1 ms |
6748 KB |
Output is correct |
41 |
Correct |
2 ms |
6748 KB |
Output is correct |
42 |
Correct |
1 ms |
6748 KB |
Output is correct |
43 |
Correct |
2 ms |
6748 KB |
Output is correct |
44 |
Correct |
2 ms |
6748 KB |
Output is correct |
45 |
Correct |
3 ms |
6748 KB |
Output is correct |
46 |
Correct |
2 ms |
6748 KB |
Output is correct |
47 |
Correct |
2 ms |
6748 KB |
Output is correct |
48 |
Correct |
39 ms |
13936 KB |
Output is correct |
49 |
Correct |
45 ms |
14548 KB |
Output is correct |
50 |
Correct |
42 ms |
14676 KB |
Output is correct |
51 |
Correct |
35 ms |
13352 KB |
Output is correct |
52 |
Correct |
45 ms |
14540 KB |
Output is correct |
53 |
Correct |
38 ms |
13776 KB |
Output is correct |
54 |
Correct |
26 ms |
15056 KB |
Output is correct |
55 |
Correct |
56 ms |
21968 KB |
Output is correct |
56 |
Correct |
53 ms |
17860 KB |
Output is correct |
57 |
Correct |
48 ms |
16840 KB |
Output is correct |
58 |
Correct |
49 ms |
15572 KB |
Output is correct |
59 |
Correct |
47 ms |
14484 KB |
Output is correct |
60 |
Correct |
31 ms |
14680 KB |
Output is correct |
61 |
Correct |
36 ms |
14756 KB |
Output is correct |
62 |
Correct |
45 ms |
14792 KB |
Output is correct |
63 |
Correct |
35 ms |
14552 KB |
Output is correct |
64 |
Correct |
37 ms |
14800 KB |
Output is correct |
65 |
Correct |
35 ms |
14992 KB |
Output is correct |
66 |
Correct |
47 ms |
14548 KB |
Output is correct |
67 |
Correct |
26 ms |
13268 KB |
Output is correct |
68 |
Correct |
30 ms |
14032 KB |
Output is correct |
69 |
Correct |
34 ms |
15060 KB |
Output is correct |
70 |
Correct |
34 ms |
14456 KB |
Output is correct |
71 |
Correct |
31 ms |
13256 KB |
Output is correct |
72 |
Correct |
29 ms |
13784 KB |
Output is correct |
73 |
Correct |
36 ms |
15048 KB |
Output is correct |
74 |
Correct |
32 ms |
14460 KB |
Output is correct |
75 |
Correct |
51 ms |
14508 KB |
Output is correct |
76 |
Correct |
40 ms |
14292 KB |
Output is correct |
77 |
Correct |
37 ms |
14544 KB |
Output is correct |
78 |
Correct |
26 ms |
12596 KB |
Output is correct |
79 |
Correct |
30 ms |
13380 KB |
Output is correct |
80 |
Correct |
42 ms |
14280 KB |
Output is correct |
81 |
Correct |
51 ms |
14800 KB |
Output is correct |
82 |
Correct |
34 ms |
14796 KB |
Output is correct |