Submission #737130

# Submission time Handle Problem Language Result Execution time Memory
737130 2023-05-06T16:44:56 Z penguin133 Village (BOI20_village) C++17
50 / 100
105 ms 38412 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int S[200005], cnt = 1, E[200005], p[20][200005];
vector <int> adj[200005];
int n, dep[200005];

void dfs(int x, int par, int d){
	S[x] = cnt++;
	p[0][x] = par;
	dep[x] = d;
	for(auto i : adj[x]){
		if(i == par)continue;
		dfs(i, x, d + 1);
	}
}

int lca(int u, int v){
	if(dep[u] > dep[v])swap(u, v);
	int diff = dep[v] - dep[u];
	for(int i=19;i>=0;i--)if(diff >> i & 1)v = p[i][v];
	if(u == v)return u;
	for(int i=19;i>=0;i--){
		if(p[i][u] != p[i][v])u = p[i][u], v = p[i][v];
	}
	return p[0][u];
}
int hv[200005], ans, bru[200005], f = 0;
void grr(int x, int par){
	vector <int> tmp;
	for(auto i : adj[x]){
		if(i == par)continue;
		grr(i, x);
		if(hv[i])tmp.push_back(i);
	}
	bool g = 1;
	if((int)tmp.size() >= 2 && (int)tmp.size()%2 == 0){
		int xx = tmp.back(); tmp.pop_back();
		int y = tmp.back(); tmp.pop_back();
		ans += 2;
		bru[x] = xx;
		bru[xx] = y;
		bru[y] = x;
		f = 1;
		g = 0;
	}
	while((int)tmp.size() >= 2){
		int xx = tmp.back(); tmp.pop_back();
		int y = tmp.back(); tmp.pop_back();
		ans += 2;
		bru[xx] = y, bru[y] = xx;
	}
	if(tmp.empty())hv[x] = g;
	else ans++, bru[x] = tmp[0], bru[tmp[0]] = x;
}
int B[500005];
void solve(){
	cin >> n;
	for(int i=1;i<n;i++){
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1, -1, 1);
	for(int i=1;i<=19;i++)for(int j=1;j<=n;j++)p[i][j] = p[i-1][p[i-1][j]];
	grr(1, -1);
	if(hv[1]){
		int x = adj[1][0];
		int y = bru[x];
		if(bru[y] == x){
			
			ans++;
			bru[1] = x, bru[x] = y, bru[y] = 1;
		}
		else{
			int z = bru[y];
			bru[z] = y;
			bru[1] = x; bru[x] = 1;
			ans++;
		}
	}
	cout << ans * 2 << ' ' << 0 << '\n';
	for(int i=1;i<=n;i++)cout << bru[i] << ' ';
	cout << '\n';
	for(int i=1;i<=n;i++)cout << i << ' ';
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

Village.cpp:98:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   98 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 5076 KB Partially correct
2 Partially correct 4 ms 5076 KB Partially correct
3 Partially correct 3 ms 5076 KB Partially correct
4 Partially correct 2 ms 5076 KB Partially correct
5 Partially correct 2 ms 5076 KB Partially correct
6 Partially correct 3 ms 5076 KB Partially correct
7 Partially correct 3 ms 5076 KB Partially correct
8 Partially correct 3 ms 5076 KB Partially correct
9 Partially correct 4 ms 5076 KB Partially correct
10 Partially correct 3 ms 5076 KB Partially correct
11 Partially correct 4 ms 5076 KB Partially correct
12 Partially correct 3 ms 5076 KB Partially correct
13 Partially correct 3 ms 5076 KB Partially correct
14 Partially correct 3 ms 5076 KB Partially correct
15 Partially correct 3 ms 5172 KB Partially correct
16 Partially correct 3 ms 5164 KB Partially correct
17 Partially correct 3 ms 5076 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 5204 KB Partially correct
2 Partially correct 4 ms 5204 KB Partially correct
3 Partially correct 3 ms 5204 KB Partially correct
4 Partially correct 4 ms 5332 KB Partially correct
5 Partially correct 3 ms 5332 KB Partially correct
6 Partially correct 3 ms 5424 KB Partially correct
7 Partially correct 3 ms 5424 KB Partially correct
8 Partially correct 3 ms 5332 KB Partially correct
9 Partially correct 3 ms 5332 KB Partially correct
10 Partially correct 3 ms 5420 KB Partially correct
11 Partially correct 4 ms 5460 KB Partially correct
12 Partially correct 4 ms 5460 KB Partially correct
13 Partially correct 4 ms 5460 KB Partially correct
14 Partially correct 4 ms 5332 KB Partially correct
15 Partially correct 3 ms 5332 KB Partially correct
16 Partially correct 3 ms 5332 KB Partially correct
17 Partially correct 4 ms 5336 KB Partially correct
18 Partially correct 3 ms 5428 KB Partially correct
19 Partially correct 3 ms 5420 KB Partially correct
20 Partially correct 3 ms 5428 KB Partially correct
21 Partially correct 3 ms 5436 KB Partially correct
22 Partially correct 4 ms 5332 KB Partially correct
23 Partially correct 4 ms 5296 KB Partially correct
24 Partially correct 4 ms 5296 KB Partially correct
25 Partially correct 5 ms 5204 KB Partially correct
26 Partially correct 3 ms 5428 KB Partially correct
27 Partially correct 3 ms 5204 KB Partially correct
28 Partially correct 3 ms 5428 KB Partially correct
29 Partially correct 3 ms 5332 KB Partially correct
30 Partially correct 4 ms 5332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 5076 KB Partially correct
2 Partially correct 4 ms 5076 KB Partially correct
3 Partially correct 3 ms 5076 KB Partially correct
4 Partially correct 2 ms 5076 KB Partially correct
5 Partially correct 2 ms 5076 KB Partially correct
6 Partially correct 3 ms 5076 KB Partially correct
7 Partially correct 3 ms 5076 KB Partially correct
8 Partially correct 3 ms 5076 KB Partially correct
9 Partially correct 4 ms 5076 KB Partially correct
10 Partially correct 3 ms 5076 KB Partially correct
11 Partially correct 4 ms 5076 KB Partially correct
12 Partially correct 3 ms 5076 KB Partially correct
13 Partially correct 3 ms 5076 KB Partially correct
14 Partially correct 3 ms 5076 KB Partially correct
15 Partially correct 3 ms 5172 KB Partially correct
16 Partially correct 3 ms 5164 KB Partially correct
17 Partially correct 3 ms 5076 KB Partially correct
18 Partially correct 4 ms 5204 KB Partially correct
19 Partially correct 4 ms 5204 KB Partially correct
20 Partially correct 3 ms 5204 KB Partially correct
21 Partially correct 4 ms 5332 KB Partially correct
22 Partially correct 3 ms 5332 KB Partially correct
23 Partially correct 3 ms 5424 KB Partially correct
24 Partially correct 3 ms 5424 KB Partially correct
25 Partially correct 3 ms 5332 KB Partially correct
26 Partially correct 3 ms 5332 KB Partially correct
27 Partially correct 3 ms 5420 KB Partially correct
28 Partially correct 4 ms 5460 KB Partially correct
29 Partially correct 4 ms 5460 KB Partially correct
30 Partially correct 4 ms 5460 KB Partially correct
31 Partially correct 4 ms 5332 KB Partially correct
32 Partially correct 3 ms 5332 KB Partially correct
33 Partially correct 3 ms 5332 KB Partially correct
34 Partially correct 4 ms 5336 KB Partially correct
35 Partially correct 3 ms 5428 KB Partially correct
36 Partially correct 3 ms 5420 KB Partially correct
37 Partially correct 3 ms 5428 KB Partially correct
38 Partially correct 3 ms 5436 KB Partially correct
39 Partially correct 4 ms 5332 KB Partially correct
40 Partially correct 4 ms 5296 KB Partially correct
41 Partially correct 4 ms 5296 KB Partially correct
42 Partially correct 5 ms 5204 KB Partially correct
43 Partially correct 3 ms 5428 KB Partially correct
44 Partially correct 3 ms 5204 KB Partially correct
45 Partially correct 3 ms 5428 KB Partially correct
46 Partially correct 3 ms 5332 KB Partially correct
47 Partially correct 4 ms 5332 KB Partially correct
48 Partially correct 70 ms 27772 KB Partially correct
49 Partially correct 72 ms 30004 KB Partially correct
50 Partially correct 92 ms 30032 KB Partially correct
51 Partially correct 58 ms 24524 KB Partially correct
52 Partially correct 72 ms 29716 KB Partially correct
53 Partially correct 82 ms 27252 KB Partially correct
54 Partially correct 40 ms 21432 KB Partially correct
55 Partially correct 96 ms 38412 KB Partially correct
56 Partially correct 95 ms 34372 KB Partially correct
57 Partially correct 105 ms 32644 KB Partially correct
58 Partially correct 83 ms 31436 KB Partially correct
59 Partially correct 99 ms 30156 KB Partially correct
60 Partially correct 53 ms 30148 KB Partially correct
61 Partially correct 67 ms 30360 KB Partially correct
62 Partially correct 84 ms 30332 KB Partially correct
63 Partially correct 63 ms 28868 KB Partially correct
64 Partially correct 77 ms 30428 KB Partially correct
65 Partially correct 65 ms 30540 KB Partially correct
66 Partially correct 61 ms 28964 KB Partially correct
67 Partially correct 44 ms 24084 KB Partially correct
68 Partially correct 54 ms 26588 KB Partially correct
69 Partially correct 64 ms 30748 KB Partially correct
70 Partially correct 63 ms 28952 KB Partially correct
71 Partially correct 40 ms 22732 KB Partially correct
72 Partially correct 45 ms 25136 KB Partially correct
73 Partially correct 82 ms 30504 KB Partially correct
74 Partially correct 54 ms 28356 KB Partially correct
75 Partially correct 77 ms 30536 KB Partially correct
76 Partially correct 70 ms 29920 KB Partially correct
77 Partially correct 79 ms 29228 KB Partially correct
78 Partially correct 45 ms 21912 KB Partially correct
79 Partially correct 50 ms 24516 KB Partially correct
80 Partially correct 83 ms 30568 KB Partially correct
81 Partially correct 62 ms 29388 KB Partially correct
82 Partially correct 63 ms 29920 KB Partially correct