Submission #314416

# Submission time Handle Problem Language Result Execution time Memory
314416 2020-10-19T20:19:54 Z sofapuden Village (BOI20_village) C++14
75 / 100
115 ms 19192 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> gra;
vector<int> posmin, posmax, sz, dec1, dec2;

vector<bool> used;

int ansmin = 0, ansmax = 0, n, cnt = 0;

void dfs(int x, int p){
	sz[x] = 1;
	for(auto i : gra[x]){
		if(i == p)continue;
		dfs(i,x);
		sz[x]+=sz[i];
		if(used[i])continue;
		used[x] = true;
		swap(posmin[x],posmin[i]);
		ansmin += 2;
	}
	if(x)ansmax += min(sz[x], n-sz[x])*2;
	else if(!used[0]){
		swap(posmin[0], posmin[gra[0][0]]);
		ansmin+=2;
	}
}
void findroot(int x, int p){
	for(auto i : gra[x]){
		if(i == p)continue;
		if(sz[i] > n/2){
			dec1[i] = 0;
			dec2[0] = i;
			findroot(i,x);
		}
	}
}
void encode(int x, int p){
	dec1[cnt] = x;
	dec2[x] = cnt++;
	for(auto i : gra[x]){
		if(i == p)continue;
		encode(i,x);
	}
}
	
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	gra.resize(n);
	posmin.resize(n);
	posmax.resize(n);
	dec1.resize(n);
	dec2.resize(n);
	sz.resize(n);
	used.resize(n,false);
	iota(posmin.begin(), posmin.end(), 0);
	iota(posmax.begin(), posmax.end(), 0);
	for(int i = 0; i < n-1; ++i){
		int a, b; cin >> a >> b; a--; b--;
		gra[a].push_back(b);
		gra[b].push_back(a);
	}
	dfs(0,0);
	findroot(0,0);
	encode(dec1[0],dec1[0]);
	for(int i = 0; i < n; ++i){
		posmax[i] = dec1[(dec2[i]+n/2)%n];
	}
	cout << ansmin << " " << ansmax << "\n";
	for(auto x : posmin)cout << x+1 << " ";
	cout << "\n";
	for(auto x : posmax)cout << x+1 << " ";
	cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 640 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 1 ms 512 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 640 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 512 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 76 ms 9336 KB Output is correct
49 Correct 90 ms 10232 KB Output is correct
50 Correct 89 ms 10360 KB Output is correct
51 Correct 59 ms 8056 KB Output is correct
52 Correct 83 ms 10104 KB Output is correct
53 Correct 75 ms 9208 KB Output is correct
54 Correct 45 ms 9464 KB Output is correct
55 Partially correct 115 ms 19192 KB Partially correct
56 Partially correct 104 ms 14456 KB Partially correct
57 Correct 100 ms 13048 KB Output is correct
58 Correct 95 ms 11640 KB Output is correct
59 Correct 82 ms 10360 KB Output is correct
60 Correct 59 ms 10604 KB Output is correct
61 Correct 63 ms 10716 KB Output is correct
62 Correct 69 ms 10616 KB Output is correct
63 Correct 63 ms 9976 KB Output is correct
64 Correct 76 ms 10616 KB Output is correct
65 Correct 67 ms 10744 KB Output is correct
66 Correct 62 ms 10012 KB Output is correct
67 Correct 43 ms 7928 KB Output is correct
68 Correct 58 ms 9080 KB Output is correct
69 Correct 67 ms 10744 KB Output is correct
70 Correct 63 ms 10104 KB Output is correct
71 Correct 42 ms 7544 KB Output is correct
72 Correct 51 ms 8568 KB Output is correct
73 Correct 67 ms 10744 KB Output is correct
74 Correct 60 ms 9848 KB Output is correct
75 Correct 87 ms 10104 KB Output is correct
76 Correct 82 ms 10104 KB Output is correct
77 Correct 70 ms 10104 KB Output is correct
78 Correct 45 ms 7032 KB Output is correct
79 Correct 53 ms 8060 KB Output is correct
80 Correct 97 ms 10232 KB Output is correct
81 Correct 74 ms 10232 KB Output is correct
82 Correct 67 ms 10488 KB Output is correct