#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
vector<int> adj[N];
int ans[N], sol;
void Dfs(int s, int e) {
for (auto u : adj[s]) {
if (u == e) continue;
Dfs(u, s);
if (ans[u] == u) {
swap(ans[u], ans[s]);
sol += 2;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) ans[i] = i;
Dfs(1, 0);
if (ans[1] == 1) {
swap(ans[1], ans[adj[1][0]]);
sol += 2;
}
cout << sol << en;
for (int i = 1; i <= n; i++) cout << ans[i] << sp;
cout << en;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |