Submission #1130609

#TimeUsernameProblemLanguageResultExecution timeMemory
1130609rayan_bdVillage (BOI20_village)C++20
0 / 100
4 ms4932 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i] #define show(n) cout<<n<<'\n' #define all(v) v.begin(), v.end() #define br cout<<"\n" #define pb push_back #define nl '\n' #define yes cout<<"YES\n" #define no cout<<"NO\n" #define ret return #define ll long long #define ld long double #define sza(x) ((int)x.size()) #define fi first #define se second const int mxN = 1e5 + 5; const ll MOD = 1e9 + 7; const ll INF = 1e9; const ld EPS = 1e-9; vector<ll> adj[mxN],new_adj[mxN]; bool changed1[mxN],changed2[mxN]; ll ans1=0,ans2=0,pos1[mxN],pos2[mxN]; void dfs(ll u=1,ll par=-1){ ll cnt=0; for(auto it:new_adj[u]){ if(it!=par){ dfs(it,u); if(!changed1[it]) ++cnt; } } ans1+=cnt*2; if(cnt>0){ if(par!=-1){ adj[u].erase(find(all(adj[u]),par)); adj[par].erase(find(all(adj[par]),u)); } pos1[adj[u][0]]=u; pos1[u]=adj[u].back(); changed1[u]=1; for(ll i=1;i<adj[u].size();++i){ pos1[adj[u][i]]=adj[u][i-1]; } } if(u==1&&cnt==0){ ans1+=2; pos1[u]=1; swap(pos1[u],pos1[new_adj[u][0]]); } } void lets_go() { ll n,u,v;cin>>n; for(ll i=0;i<n-1;++i){ cin>>u>>v; adj[u].pb(v); adj[v].pb(u); new_adj[u].pb(v); new_adj[v].pb(u); } dfs(); cout<<ans1<<" "<<ans2<<nl; for(ll i=1;i<=n;++i) cout<<pos1[i]<<" "; br; for(ll i=1;i<=n;++i) cout<<pos2[i]<<" "; br; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); lets_go(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...