답안 #737117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737117 2023-05-06T16:16:17 Z penguin133 Village (BOI20_village) C++17
0 / 100
4 ms 5204 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);
	}
	if((int)tmp.size() >= 2 && !f && n%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;
	}
	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] = 1;
	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(!f && n % 2){
		int x = adj[1][0];
		int y = bru[x];
		ans++;
		bru[1] = x, bru[x] = y, bru[y] = 1;
	}
	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:87:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 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 3 ms 5076 KB Partially correct
5 Partially correct 3 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 3 ms 5076 KB Partially correct
10 Partially correct 3 ms 5076 KB Partially correct
11 Partially correct 3 ms 5076 KB Partially correct
12 Partially correct 3 ms 5076 KB Partially correct
13 Incorrect 3 ms 5076 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 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 3 ms 5076 KB Partially correct
5 Partially correct 3 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 3 ms 5076 KB Partially correct
10 Partially correct 3 ms 5076 KB Partially correct
11 Partially correct 3 ms 5076 KB Partially correct
12 Partially correct 3 ms 5076 KB Partially correct
13 Incorrect 3 ms 5076 KB Output isn't correct
14 Halted 0 ms 0 KB -