제출 #1049524

#제출 시각아이디문제언어결과실행 시간메모리
1049524EntityPlanttMake them Meet (EGOI24_makethemmeet)C++17
70 / 100
2 ms600 KiB
#include <iostream>
#include <vector>
using namespace std;

vector <int> graph[100];
int depth[100], parent[100];
void dfs(int u) {
	for (int &v : graph[u]) {
		if (v == parent[u]) continue;
		parent[v] = u;
		depth[v] = depth[u] + 1;
		dfs(v);
	}
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, a, b;
	cin >> n >> a;
	if (a >= n) {
		cout << n * 2 + 10 << '\n';
		for (int i = 0; i < n + 5; i++) {
			for (int j = 0; j < n; j++) cout << j / 2 << ' ';
			cout << '\n';
			for (int j = 0; j < n; j++) cout << (j + 1) / 2 << ' ';
			cout << '\n';
		}
		return 0;
	}
	cout << 3 * n / 2 * 2;
	for (int i = 1; i < n; i++) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	a = 0; b = -1;
	while (graph[a].size() > 1) {
		if (b == graph[a][0]) {
			b = a;
			a = graph[a][1];
		}
		else {
			b = a;
			a = graph[a][0];
		}
	}
	parent[a] = a;
	dfs(a);
	for (int i = 0; i < 3 * n / 2; i++) {
		cout << '\n';
		for (int j = 0; j < n; j++) cout << (depth[j] & 1 ? parent[j] : j) << ' ';
		cout << '\n';
		for (int j = 0; j < n; j++) cout << (depth[j] & 1 ? parent[j] : parent[parent[j]]) << ' ';
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...