Submission #605199

#TimeUsernameProblemLanguageResultExecution timeMemory
605199OttoTheDinoVillage (BOI20_village)C++17
0 / 100
2 ms2644 KiB
#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; 
      if(n==1) {cout << "1 1\n1\n";return 0;}

    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;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...