// Alir3za.Zar3 -> Shiraz , Iran
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i , l , r) for (int i=l; i<=r; i+=1)
#define arc(i , r , l) for (int i=r; i>=l; i-=1)
const int N = 1e5+7;
int n,Lo,Hi=0 , lo[N],hi[N],sz[N];
vector<int> e[N],op;
void brain_DFS (int v , int p)
{
sz[v] = 1; op.push_back(v);
for (auto to : e[v])
{
if (to == p){ continue; }
brain_DFS(to,v);
sz[v] += sz[to];
Hi += min(sz[to],n-sz[to]);
}
if (lo[v] == v)
{
if (v==p)
swap(lo[v],lo[e[v].front()]);
else
swap(lo[v],lo[p]);
Lo += 2;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
loop(i,1,n){ lo[i]=i; }
loop(i,1,n-1)
{
int u,v; cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
brain_DFS(1,1);
cout << Lo << " " << Hi << '\n';
loop(i,1,n){ cout << lo[i] << " "; }
cout << '\n';
loop(i,1,n){ cout << 1 << " "; }
cout << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |