This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e14 + 7;
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<ll> ar(ous) , mnvr(ous) , mxvr(ous);
ll mna , mxa , ct;
std::vector<ll> adj[ous];
std::vector<ll> v;
bool cmp(ll x , ll y){
return ar[x] < ar[y];
}
void jd(ll crt , ll prv){
v.pb(crt);
for(auto j:adj[crt]){
if(j != prv){
jd(j , crt);
}
}
}
void klp(ll crt){
std::sort(all(adj[crt]) , cmp);
for(auto j:adj[crt]){
jd(j , crt);
}
v.pb(crt);
for(ll i = 0;v.size()>i;i++){
mxvr[v[i]] = v[(ll)v.size() - i - 1];
mxvr[v[(ll)v.size() - i - 1]] = v[i];
}
}
void mdfs(ll crt , ll prv){
for(auto j:adj[crt]){
if(j != prv){
mdfs(j , crt);
}
}
if(crt == mnvr[crt]){
mna+=2;
if(prv == -1){
ll tmp = mnvr[crt];
mnvr[crt] = mnvr[adj[crt][0]];
mnvr[adj[crt][0]] = tmp;
}
else{
ll tmp = mnvr[crt];
mnvr[crt] = mnvr[prv];
mnvr[prv] = tmp;
}
}
}
ll fndcnt(ll crt , ll prv){
ll z = 1 , mxx = 0;
for(auto j:adj[crt]){
if(j != prv){
ll x = fndcnt(j , crt);
z+=x;
mxx += std::max(mxx , x);
}
}
if(n - z <= n/2 && n/2 >= mxx){
ct = crt;
}
return z;
}
ll fndsub(ll crt , ll prv){
ll z = 1;
for(auto j:adj[crt]){
if(j != prv){
ll x = fndsub(j , crt);
z+=x;
}
}
if(prv != -1){
mxa += std::min(z , n - z) * 2;
}
ar[crt] = z;
return z;
}
void solve(){
std::cin >> n;
for(ll i = 1;n>i;i++){
ll x , y;std::cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
for(ll i = 0;n>=i;i++){
mnvr[i] = i;
mxvr[i] = i;
}
mdfs(1 , -1);
fndcnt(1 , -1);
fndsub(ct , -1);
klp(ct);
std::cout << mna << " " << mxa << "\n";
for(ll i = 1;n>=i;i++){
std::cout << mnvr[i] << " ";
}
std::cout << "\n";
for(ll i = 1;n>=i;i++){
std::cout << mxvr[i] << " ";
}
std::cout << "\n";
return;/**/
}
signed main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t=1;
//std::cin >> t;
ll o = 1;
while(t--){
//cout << "Case " << o++ << ":\n";
solve();
}
return 0;
}/**/
Compilation message (stderr)
Village.cpp:5:78: warning: "/*" within comment [-Wcomment]
5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
|
Village.cpp: In function 'void klp(ll)':
Village.cpp:45:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
45 | for(ll i = 0;v.size()>i;i++){
| ~~~~~~~~^~
Village.cpp: In function 'int main()':
Village.cpp:129:8: warning: unused variable 'o' [-Wunused-variable]
129 | ll o = 1;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |