#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (ll i = s; i <= e; ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define len(a) (ll)a.size()
typedef long long ll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<int> vi;
const int mx = 1e5;
vi adj[mx+1];
int ans1 = 0, go1[mx+1];
bool dfs1 (int u, int p) {
set<int> st;
for (int v : adj[u]) {
if (v==p) continue;
if (dfs1 (v, u)) st.insert(v);
}
ans1 += 2*len(st);
for (int v : st) swap (go1[u], go1[v]);
if (u==1 && len(st)%2==0) {
swap (go1[1], go1[adj[1][0]]);
ans1 += 2;
}
return len(st)%2==0;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
rep (i,1,n) go1[i] = i;
rep (i,1,n-1) {
int u, v; cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
dfs1 (1, 0);
cout << ans1 << " 1\n";
rep (i,1,n) cout << go1[i] << " \n"[i==n];
rep (i,1,n) cout << 1 << " \n"[i==n];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
3 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
4 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
2644 KB |
Partially correct |
2 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
3 |
Partially correct |
2 ms |
2644 KB |
Partially correct |
4 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |