Submission #946122

# Submission time Handle Problem Language Result Execution time Memory
946122 2024-03-14T10:36:11 Z pan Village (BOI20_village) C++17
50 / 100
60 ms 17412 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, 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)
	{
		minc[p] = from;
		minc[from] = p;
	}
}

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:
	// ans = ((n+1)/2)*2
	minval = ((n+1)/2)*2;
	dfs1(-1, 1); 
	if (minc[1]==1) swap(minc[adj[1][0]], minc[1]); // 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(1LL, ' ');
	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 Partially correct 1 ms 7260 KB Partially correct
2 Partially correct 2 ms 7260 KB Partially correct
3 Partially correct 1 ms 7260 KB Partially correct
4 Partially correct 1 ms 7260 KB Partially correct
5 Partially correct 1 ms 7260 KB Partially correct
6 Partially correct 2 ms 7260 KB Partially correct
7 Partially correct 2 ms 7260 KB Partially correct
8 Partially correct 1 ms 7260 KB Partially correct
9 Partially correct 1 ms 7260 KB Partially correct
10 Partially correct 1 ms 7256 KB Partially correct
11 Partially correct 2 ms 7260 KB Partially correct
12 Partially correct 1 ms 7260 KB Partially correct
13 Partially correct 1 ms 7260 KB Partially correct
14 Partially correct 2 ms 7260 KB Partially correct
15 Partially correct 1 ms 7260 KB Partially correct
16 Partially correct 2 ms 7260 KB Partially correct
17 Partially correct 2 ms 7256 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 7260 KB Partially correct
2 Partially correct 2 ms 7260 KB Partially correct
3 Partially correct 2 ms 7260 KB Partially correct
4 Partially correct 2 ms 7260 KB Partially correct
5 Partially correct 2 ms 7260 KB Partially correct
6 Partially correct 2 ms 7260 KB Partially correct
7 Partially correct 2 ms 7300 KB Partially correct
8 Partially correct 2 ms 7256 KB Partially correct
9 Partially correct 2 ms 7260 KB Partially correct
10 Partially correct 2 ms 7260 KB Partially correct
11 Partially correct 2 ms 7260 KB Partially correct
12 Partially correct 2 ms 7260 KB Partially correct
13 Partially correct 2 ms 7260 KB Partially correct
14 Partially correct 2 ms 7260 KB Partially correct
15 Partially correct 2 ms 7260 KB Partially correct
16 Partially correct 2 ms 7256 KB Partially correct
17 Partially correct 2 ms 7260 KB Partially correct
18 Partially correct 2 ms 7260 KB Partially correct
19 Partially correct 2 ms 7456 KB Partially correct
20 Partially correct 2 ms 7260 KB Partially correct
21 Partially correct 2 ms 7256 KB Partially correct
22 Partially correct 2 ms 7260 KB Partially correct
23 Partially correct 2 ms 7256 KB Partially correct
24 Partially correct 2 ms 7256 KB Partially correct
25 Partially correct 2 ms 7256 KB Partially correct
26 Partially correct 2 ms 7260 KB Partially correct
27 Partially correct 2 ms 7260 KB Partially correct
28 Partially correct 2 ms 7260 KB Partially correct
29 Partially correct 2 ms 7260 KB Partially correct
30 Partially correct 2 ms 7260 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 7260 KB Partially correct
2 Partially correct 2 ms 7260 KB Partially correct
3 Partially correct 1 ms 7260 KB Partially correct
4 Partially correct 1 ms 7260 KB Partially correct
5 Partially correct 1 ms 7260 KB Partially correct
6 Partially correct 2 ms 7260 KB Partially correct
7 Partially correct 2 ms 7260 KB Partially correct
8 Partially correct 1 ms 7260 KB Partially correct
9 Partially correct 1 ms 7260 KB Partially correct
10 Partially correct 1 ms 7256 KB Partially correct
11 Partially correct 2 ms 7260 KB Partially correct
12 Partially correct 1 ms 7260 KB Partially correct
13 Partially correct 1 ms 7260 KB Partially correct
14 Partially correct 2 ms 7260 KB Partially correct
15 Partially correct 1 ms 7260 KB Partially correct
16 Partially correct 2 ms 7260 KB Partially correct
17 Partially correct 2 ms 7256 KB Partially correct
18 Partially correct 2 ms 7260 KB Partially correct
19 Partially correct 2 ms 7260 KB Partially correct
20 Partially correct 2 ms 7260 KB Partially correct
21 Partially correct 2 ms 7260 KB Partially correct
22 Partially correct 2 ms 7260 KB Partially correct
23 Partially correct 2 ms 7260 KB Partially correct
24 Partially correct 2 ms 7300 KB Partially correct
25 Partially correct 2 ms 7256 KB Partially correct
26 Partially correct 2 ms 7260 KB Partially correct
27 Partially correct 2 ms 7260 KB Partially correct
28 Partially correct 2 ms 7260 KB Partially correct
29 Partially correct 2 ms 7260 KB Partially correct
30 Partially correct 2 ms 7260 KB Partially correct
31 Partially correct 2 ms 7260 KB Partially correct
32 Partially correct 2 ms 7260 KB Partially correct
33 Partially correct 2 ms 7256 KB Partially correct
34 Partially correct 2 ms 7260 KB Partially correct
35 Partially correct 2 ms 7260 KB Partially correct
36 Partially correct 2 ms 7456 KB Partially correct
37 Partially correct 2 ms 7260 KB Partially correct
38 Partially correct 2 ms 7256 KB Partially correct
39 Partially correct 2 ms 7260 KB Partially correct
40 Partially correct 2 ms 7256 KB Partially correct
41 Partially correct 2 ms 7256 KB Partially correct
42 Partially correct 2 ms 7256 KB Partially correct
43 Partially correct 2 ms 7260 KB Partially correct
44 Partially correct 2 ms 7260 KB Partially correct
45 Partially correct 2 ms 7260 KB Partially correct
46 Partially correct 2 ms 7260 KB Partially correct
47 Partially correct 2 ms 7260 KB Partially correct
48 Partially correct 43 ms 11604 KB Partially correct
49 Partially correct 52 ms 11828 KB Partially correct
50 Partially correct 48 ms 11868 KB Partially correct
51 Partially correct 41 ms 10932 KB Partially correct
52 Partially correct 48 ms 11768 KB Partially correct
53 Partially correct 43 ms 11368 KB Partially correct
54 Partially correct 27 ms 12112 KB Partially correct
55 Partially correct 60 ms 17412 KB Partially correct
56 Partially correct 59 ms 14928 KB Partially correct
57 Partially correct 54 ms 13648 KB Partially correct
58 Partially correct 52 ms 12880 KB Partially correct
59 Partially correct 48 ms 12008 KB Partially correct
60 Partially correct 41 ms 12224 KB Partially correct
61 Partially correct 41 ms 12176 KB Partially correct
62 Partially correct 52 ms 12244 KB Partially correct
63 Partially correct 41 ms 11856 KB Partially correct
64 Partially correct 45 ms 12368 KB Partially correct
65 Partially correct 45 ms 12440 KB Partially correct
66 Partially correct 40 ms 11856 KB Partially correct
67 Partially correct 34 ms 10948 KB Partially correct
68 Partially correct 38 ms 11604 KB Partially correct
69 Partially correct 49 ms 12356 KB Partially correct
70 Partially correct 40 ms 12092 KB Partially correct
71 Partially correct 43 ms 10836 KB Partially correct
72 Partially correct 37 ms 11356 KB Partially correct
73 Partially correct 43 ms 12368 KB Partially correct
74 Partially correct 38 ms 11948 KB Partially correct
75 Partially correct 49 ms 12476 KB Partially correct
76 Partially correct 53 ms 11860 KB Partially correct
77 Partially correct 44 ms 12368 KB Partially correct
78 Partially correct 29 ms 10576 KB Partially correct
79 Partially correct 47 ms 11096 KB Partially correct
80 Partially correct 58 ms 12372 KB Partially correct
81 Partially correct 48 ms 12624 KB Partially correct
82 Partially correct 45 ms 12160 KB Partially correct