Submission #916513

# Submission time Handle Problem Language Result Execution time Memory
916513 2024-01-26T03:24:44 Z NK_ Village (BOI20_village) C++17
75 / 100
78 ms 20688 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())

using ll = long long;
template<class T> using V = vector<T>;
using vi = V<int>;


int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;

	V<vi> adj(N); for(int i = 0; i < N - 1; i++) {
		int u, v; cin >> u >> v; --u, --v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	vi sub(N); function<void(int, int)> gen = [&](int u, int p) {
		sub[u] = 1;
		for(auto& v : adj[u]) if (v != p) {
			gen(v, u); sub[u] += sub[v];
		}
	};

	function<int(int, int)> find = [&](int u, int p) {
		for(auto& v : adj[u]) if (v != p) {
			if (2 * sub[v] >= N) return find(v, u);
		}

		return u;
	};

	gen(0, -1); int R = find(0, -1);

	// cout << R << endl;

	int lans = 0, gans = 0;
	vi L(N), G(N); iota(begin(L), end(L), 0);

	vi ord;
	function<int(int, int)> answer = [&](int u, int p) {
		ord.pb(u); sub[u] = 1;

		vi chd = {u};
		for(auto& v : adj[u]) if (v != p) {
			int r = answer(v, u); 
			sub[u] += sub[v];
			gans += 2 * sub[v];
			if (r != -1) chd.pb(r);
		}


		if (sz(chd) == 1) {
			lans += 2;
			return chd[0];
		}

		for(int i = 0; i < sz(chd); i++) {
			int j = (i + 1) % sz(chd);
			L[chd[j]] = chd[i];
		}

		return -1;
	};

	int r = answer(R, -1);
	if (r != -1) {
		for(auto& v : adj[R]) {
			swap(L[R], L[v]);
			break;
		}
	}

	int mx = 0;
	for(auto& v : adj[R]) mx = max(mx, sub[v]);

	for(int x = 0; x < N; x++) {
		int y = (x + mx) % N;
		G[ord[y]] = ord[x];
	}

	cout << lans << " " << gans << nl;
	
	for(auto& x : L) cout << x + 1 << " ";
	cout << nl;

	for(auto& x : G) cout << x + 1 << " ";
	cout << nl;





	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 652 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 500 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 652 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 508 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 500 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 360 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 464 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 41 ms 9164 KB Output is correct
49 Correct 47 ms 9936 KB Output is correct
50 Correct 44 ms 9944 KB Output is correct
51 Correct 34 ms 7824 KB Output is correct
52 Correct 45 ms 9932 KB Output is correct
53 Correct 38 ms 8912 KB Output is correct
54 Correct 28 ms 10200 KB Output is correct
55 Partially correct 78 ms 20688 KB Partially correct
56 Partially correct 52 ms 14924 KB Partially correct
57 Correct 53 ms 12932 KB Output is correct
58 Correct 55 ms 11464 KB Output is correct
59 Correct 44 ms 10188 KB Output is correct
60 Correct 34 ms 10232 KB Output is correct
61 Correct 35 ms 10544 KB Output is correct
62 Correct 36 ms 10436 KB Output is correct
63 Correct 34 ms 9684 KB Output is correct
64 Correct 40 ms 10204 KB Output is correct
65 Correct 39 ms 10360 KB Output is correct
66 Correct 34 ms 9820 KB Output is correct
67 Correct 27 ms 7884 KB Output is correct
68 Correct 32 ms 8812 KB Output is correct
69 Correct 37 ms 10524 KB Output is correct
70 Correct 37 ms 9756 KB Output is correct
71 Correct 26 ms 7380 KB Output is correct
72 Correct 29 ms 8396 KB Output is correct
73 Correct 38 ms 10452 KB Output is correct
74 Correct 40 ms 9672 KB Output is correct
75 Correct 47 ms 9932 KB Output is correct
76 Correct 48 ms 9928 KB Output is correct
77 Correct 39 ms 10188 KB Output is correct
78 Correct 28 ms 6932 KB Output is correct
79 Correct 38 ms 7796 KB Output is correct
80 Correct 68 ms 9904 KB Output is correct
81 Correct 60 ms 10028 KB Output is correct
82 Correct 38 ms 10188 KB Output is correct