제출 #1126691

#제출 시각아이디문제언어결과실행 시간메모리
1126691CiprianVillage (BOI20_village)C++20
12 / 100
1096 ms2784 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N=1e5+4; vector<int> adj[N]; int dfs(int s, int p, int f, int cnt){ if(s==f)return cnt; for(auto e: adj[s]){ if(e==p)continue; int r=dfs(e, s, f, cnt+1); if(r>0)return r; }return 0; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<int> a; for(int i=1; i<n; i++){ a.push_back(i); int u,v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); }a.push_back(n); vector<int> small(n+1), largest(n+1); int mn=1e9, mx=0; do{ bool check=true; for(int i=0; i<n; i++){ if(a[i]==i+1)check=false; }if(check){ int sum=0; for(int i=0; i<n; i++){ sum+=dfs(a[i], a[i], i+1, 0); }if(sum>mx){ mx=sum; for(int i=0; i<n; i++){ largest[i]=a[i]; } }if(sum<mn){ mn=sum; for(int i=0; i<n; i++){ small[i]=a[i]; } } } }while(next_permutation(a.begin(), a.end())); cout<<mn<<" "<<mx<<endl; for(int j=0; j<n; j++){ cout<<small[j]<<" "; }cout<<endl; for(int j=0; j<n; j++){ cout<<largest[j]<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...