Submission #713397

#TimeUsernameProblemLanguageResultExecution timeMemory
713397ammar2000Village (BOI20_village)C++17
50 / 100
142 ms19596 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define F first #define S second #define coy cout<<"YES\n" #define con cout<<"NO\n" #define co1 cout<<"-1\n" #define sc(x) scanf("%lld",&x) #define all(x) x.begin(),x.end() #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const int SI=2e5+7; ll INF=8e18+7; int MOD=1e9+7; int dx[] = {1 , -1 , 0 , 0}; int dy[] = {0 , 0 , 1 , -1}; int T=1; ll ss; ll n,dp[SI],up[SI],ans[SI]; vector < ll> v[SI]; void bt( int x=1,int pa=0) { for (auto i:v[x]) { if (i==pa) continue; bt(i,x); if (up[i]==0) { swap(ans[x],ans[i]); ss+=2; up[x]=1; } } } void solver() { cin>>n; ans[n]=n; for (int i=1;i<n;i++) { ans[i]=i; int a,b; cin>>a>>b; v[a].pb(b); v[b].pb(a); } bt(); if(ans[1]==1) ss+=2,swap(ans[1],ans[v[1].back()]); cout <<ss<<" 0\n"; for (int i=1;i<=n;i++) cout <<ans[i]<<" "; for (int i=1;i<=n;i++) cout <<ans[i]<<" "; } int main() { //fast while (T--) solver(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...