Submission #946146

# Submission time Handle Problem Language Result Execution time Memory
946146 2024-03-14T10:57:14 Z pan Village (BOI20_village) C++17
100 / 100
59 ms 17704 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, x, y, minval = 0, maxval = 0, label = -1;
vector<ll> adj[100005];
ll minc[100005], maxc[100005], size1[100005], depth[100005], in[100005], conv[100005];
void dfs1(ll p, ll from)
{
	size1[from] = 1;
	for (ll u: adj[from]) if(p!=u) {dfs1(from, u); size1[from]+=size1[u];}
	if (p!=-1 && minc[from]==from)
	{
		swap(minc[from], minc[p]);
        minval+=2;
	}
}
 
ll find_centroid(ll p, ll from)
{
	for (ll u: adj[from])
	{
		if (u==p) continue;
		if (size1[u]>n/2) return find_centroid(from, u);
	}
	return from;
}
 
void dfs2(ll p, ll from)
{
	in[from]= ++label;
	conv[label] = from;
	maxval += depth[from]*2;
	for (ll u: adj[from])
	{
		if (u==p) continue;
		depth[u] = depth[from]+1;
		dfs2(from, u);
	}
}
int main()
{
	input(n);
	for (ll i=1; i<=n; ++i) minc[i] = maxc[i] = i;
	for (ll i=0; i<n-1; ++i)
	{
		input2(x, y);
		adj[x].pb(y);
		adj[y].pb(x);
	}
	// Minimum:
	dfs1(-1, 1); 
	if (minc[1]==1) {swap(minc[adj[1][0]], minc[1]); minval+=2;}// odd n lead to 1 without paur
	
	
	// Maximum:
	// Find centroid, ensure that all ppl change to house that is out of its centroid subtree
	// i to be paired with (i+ (n)/2)%n
	// As all |subtree| < n/2, his ensure that both are from different subtree
	// This is optimal.
	ll centroid = find_centroid(-1, 1);
	depth[centroid] = 0;
	dfs2(-1, centroid);
	for (ll i=1; i<=n; ++i)
	{
		ll in1 = in[i];
		ll in2 = (in1 + n/2)%n;
		maxc[conv[in2]] = i;
	}
	// output
	cout << minval << ' ' << maxval << '\n';
	for (ll i=1; i<=n; ++i) print(minc[i], ' ');
	cout << '\n';
	for (ll i=1; i<=n; ++i) print(maxc[i], ' ');
	
	return 0;
}

Compilation message

Village.cpp: In function 'int main()':
Village.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
Village.cpp:68:2: note: in expansion of macro 'input'
   68 |  input(n);
      |  ^~~~~
Village.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
Village.cpp:72:3: note: in expansion of macro 'input2'
   72 |   input2(x, y);
      |   ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 2 ms 7256 KB Output is correct
6 Correct 1 ms 7260 KB Output is correct
7 Correct 1 ms 7260 KB Output is correct
8 Correct 1 ms 7300 KB Output is correct
9 Correct 2 ms 7060 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 1 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 1 ms 7256 KB Output is correct
15 Correct 1 ms 7260 KB Output is correct
16 Correct 1 ms 7260 KB Output is correct
17 Correct 1 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7260 KB Output is correct
5 Correct 2 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Correct 2 ms 7260 KB Output is correct
8 Correct 2 ms 7260 KB Output is correct
9 Correct 2 ms 7260 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 2 ms 7260 KB Output is correct
15 Correct 2 ms 7256 KB Output is correct
16 Correct 2 ms 7260 KB Output is correct
17 Correct 2 ms 7260 KB Output is correct
18 Correct 2 ms 7260 KB Output is correct
19 Correct 2 ms 7256 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 3 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 2 ms 7260 KB Output is correct
30 Correct 2 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 2 ms 7256 KB Output is correct
6 Correct 1 ms 7260 KB Output is correct
7 Correct 1 ms 7260 KB Output is correct
8 Correct 1 ms 7300 KB Output is correct
9 Correct 2 ms 7060 KB Output is correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7260 KB Output is correct
12 Correct 1 ms 7260 KB Output is correct
13 Correct 2 ms 7260 KB Output is correct
14 Correct 1 ms 7256 KB Output is correct
15 Correct 1 ms 7260 KB Output is correct
16 Correct 1 ms 7260 KB Output is correct
17 Correct 1 ms 7260 KB Output is correct
18 Correct 1 ms 7256 KB Output is correct
19 Correct 2 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 2 ms 7260 KB Output is correct
22 Correct 2 ms 7260 KB Output is correct
23 Correct 2 ms 7260 KB Output is correct
24 Correct 2 ms 7260 KB Output is correct
25 Correct 2 ms 7260 KB Output is correct
26 Correct 2 ms 7260 KB Output is correct
27 Correct 2 ms 7260 KB Output is correct
28 Correct 2 ms 7260 KB Output is correct
29 Correct 2 ms 7260 KB Output is correct
30 Correct 2 ms 7260 KB Output is correct
31 Correct 2 ms 7260 KB Output is correct
32 Correct 2 ms 7256 KB Output is correct
33 Correct 2 ms 7260 KB Output is correct
34 Correct 2 ms 7260 KB Output is correct
35 Correct 2 ms 7260 KB Output is correct
36 Correct 2 ms 7256 KB Output is correct
37 Correct 2 ms 7260 KB Output is correct
38 Correct 2 ms 7260 KB Output is correct
39 Correct 2 ms 7260 KB Output is correct
40 Correct 2 ms 7260 KB Output is correct
41 Correct 2 ms 7260 KB Output is correct
42 Correct 2 ms 7260 KB Output is correct
43 Correct 3 ms 7260 KB Output is correct
44 Correct 2 ms 7260 KB Output is correct
45 Correct 2 ms 7260 KB Output is correct
46 Correct 2 ms 7260 KB Output is correct
47 Correct 2 ms 7512 KB Output is correct
48 Correct 45 ms 11860 KB Output is correct
49 Correct 50 ms 12368 KB Output is correct
50 Correct 50 ms 12368 KB Output is correct
51 Correct 50 ms 11088 KB Output is correct
52 Correct 48 ms 12540 KB Output is correct
53 Correct 43 ms 11804 KB Output is correct
54 Correct 28 ms 12364 KB Output is correct
55 Correct 59 ms 17704 KB Output is correct
56 Correct 55 ms 14976 KB Output is correct
57 Correct 52 ms 14164 KB Output is correct
58 Correct 51 ms 13224 KB Output is correct
59 Correct 50 ms 12368 KB Output is correct
60 Correct 41 ms 12488 KB Output is correct
61 Correct 43 ms 12672 KB Output is correct
62 Correct 48 ms 12628 KB Output is correct
63 Correct 55 ms 12372 KB Output is correct
64 Correct 54 ms 12624 KB Output is correct
65 Correct 51 ms 12812 KB Output is correct
66 Correct 41 ms 12360 KB Output is correct
67 Correct 33 ms 11224 KB Output is correct
68 Correct 37 ms 12064 KB Output is correct
69 Correct 53 ms 12884 KB Output is correct
70 Correct 41 ms 12380 KB Output is correct
71 Correct 30 ms 11088 KB Output is correct
72 Correct 46 ms 11604 KB Output is correct
73 Correct 47 ms 12768 KB Output is correct
74 Correct 40 ms 12368 KB Output is correct
75 Correct 54 ms 12744 KB Output is correct
76 Correct 51 ms 12116 KB Output is correct
77 Correct 48 ms 12892 KB Output is correct
78 Correct 31 ms 10844 KB Output is correct
79 Correct 35 ms 11344 KB Output is correct
80 Correct 49 ms 12736 KB Output is correct
81 Correct 54 ms 13032 KB Output is correct
82 Correct 54 ms 12372 KB Output is correct