답안 #946129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946129 2024-03-14T10:39:52 Z pan Village (BOI20_village) C++17
50 / 100
71 ms 17600 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) swap(minc[from], minc[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(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:64:2: note: in expansion of macro 'input'
   64 |  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:68:3: note: in expansion of macro 'input2'
   68 |   input2(x, y);
      |   ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7256 KB Output is correct
2 Correct 1 ms 7256 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 1 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Partially correct 1 ms 7260 KB Partially correct
8 Partially correct 1 ms 7256 KB Partially correct
9 Partially correct 2 ms 7256 KB Partially correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7512 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Partially correct 1 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 1 ms 7260 KB Partially correct
17 Partially correct 1 ms 7260 KB Partially correct
# 결과 실행 시간 메모리 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 7512 KB Partially correct
6 Partially correct 2 ms 7260 KB Partially correct
7 Correct 2 ms 7260 KB Output is correct
8 Partially correct 2 ms 7260 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 7256 KB Partially correct
12 Partially correct 2 ms 7256 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 7508 KB Partially correct
18 Partially correct 2 ms 7512 KB Partially correct
19 Partially correct 2 ms 7256 KB Partially correct
20 Partially correct 2 ms 7364 KB Partially correct
21 Partially correct 2 ms 7260 KB Partially correct
22 Partially correct 2 ms 7256 KB Partially correct
23 Partially correct 2 ms 7256 KB Partially correct
24 Partially correct 2 ms 7260 KB Partially correct
25 Partially correct 2 ms 7260 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 7256 KB Partially correct
29 Partially correct 2 ms 7260 KB Partially correct
30 Partially correct 2 ms 7260 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7256 KB Output is correct
2 Correct 1 ms 7256 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 1 ms 7260 KB Output is correct
5 Correct 1 ms 7260 KB Output is correct
6 Correct 2 ms 7260 KB Output is correct
7 Partially correct 1 ms 7260 KB Partially correct
8 Partially correct 1 ms 7256 KB Partially correct
9 Partially correct 2 ms 7256 KB Partially correct
10 Correct 2 ms 7260 KB Output is correct
11 Correct 2 ms 7512 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Partially correct 1 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 1 ms 7260 KB Partially correct
17 Partially correct 1 ms 7260 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 7512 KB Partially correct
23 Partially correct 2 ms 7260 KB Partially correct
24 Correct 2 ms 7260 KB Output is correct
25 Partially correct 2 ms 7260 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 7256 KB Partially correct
29 Partially correct 2 ms 7256 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 7508 KB Partially correct
35 Partially correct 2 ms 7512 KB Partially correct
36 Partially correct 2 ms 7256 KB Partially correct
37 Partially correct 2 ms 7364 KB Partially correct
38 Partially correct 2 ms 7260 KB Partially correct
39 Partially correct 2 ms 7256 KB Partially correct
40 Partially correct 2 ms 7256 KB Partially correct
41 Partially correct 2 ms 7260 KB Partially correct
42 Partially correct 2 ms 7260 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 7256 KB Partially correct
46 Partially correct 2 ms 7260 KB Partially correct
47 Partially correct 2 ms 7260 KB Partially correct
48 Partially correct 44 ms 11908 KB Partially correct
49 Partially correct 53 ms 12196 KB Partially correct
50 Partially correct 65 ms 12372 KB Partially correct
51 Partially correct 38 ms 11088 KB Partially correct
52 Partially correct 53 ms 12308 KB Partially correct
53 Partially correct 43 ms 11644 KB Partially correct
54 Correct 40 ms 12368 KB Output is correct
55 Correct 62 ms 17600 KB Output is correct
56 Partially correct 54 ms 14996 KB Partially correct
57 Partially correct 56 ms 14060 KB Partially correct
58 Partially correct 54 ms 13276 KB Partially correct
59 Partially correct 49 ms 12372 KB Partially correct
60 Partially correct 45 ms 12484 KB Partially correct
61 Partially correct 43 ms 12364 KB Partially correct
62 Partially correct 46 ms 12776 KB Partially correct
63 Partially correct 43 ms 12368 KB Partially correct
64 Partially correct 47 ms 12612 KB Partially correct
65 Partially correct 43 ms 12884 KB Partially correct
66 Partially correct 67 ms 12372 KB Partially correct
67 Partially correct 33 ms 11220 KB Partially correct
68 Partially correct 39 ms 12120 KB Partially correct
69 Partially correct 63 ms 12880 KB Partially correct
70 Partially correct 55 ms 12540 KB Partially correct
71 Partially correct 30 ms 11092 KB Partially correct
72 Partially correct 37 ms 11600 KB Partially correct
73 Partially correct 58 ms 12800 KB Partially correct
74 Partially correct 46 ms 12372 KB Partially correct
75 Partially correct 54 ms 12820 KB Partially correct
76 Partially correct 50 ms 12076 KB Partially correct
77 Partially correct 50 ms 13072 KB Partially correct
78 Partially correct 31 ms 10840 KB Partially correct
79 Partially correct 36 ms 11344 KB Partially correct
80 Partially correct 71 ms 13136 KB Partially correct
81 Partially correct 54 ms 12892 KB Partially correct
82 Partially correct 49 ms 12388 KB Partially correct