이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |