제출 #1285775

#제출 시각아이디문제언어결과실행 시간메모리
1285775tdkhaiVillage (BOI20_village)C++20
0 / 100
1 ms12088 KiB
/* _.-- ,.--. .' .' / @ |'..--------._ / \._/ '. / .-.- \ ( / \ \ \\ '. | # \\ \ -. / :\ | )._____.' \ " | / \ | \ ) | |./' :__ \.-' '--' */ #include<bits/stdc++.h> #define ll long long #define llll pair<ll,ll> #define ii pair<int,int> #define fi first #define se second #define FOR(i,l,r) for(int i=l;i<=r;i++) #define FOD(i,r,l) for(int i=r;i>=l;i--) #define ull unsigned long long #define iii pair<int,ii> #define iv pair<pii,ii> #define db double #define ld long double #define pb push_back #define tdk "kfph" using namespace std; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const int dxx[] = {1, 1, -1, -1, 2, 2, -2, -2}; const int dyy[] = {2, -2, 2, -2, 1, -1, 1, -1}; const ll INF=1e18; const int N=1e5+5; vector<int> a,g[N]; int n; ll res; int ans[N],sz[N],cen; void dfs(int u,int par) { sz[u]=1; for(int v:g[u]) { if(v!=par) { dfs(v,u); sz[u]+=sz[v]; } } } int findc(int u,int par) { for(int v:g[u]) { if(sz[v]*2>sz[1] and v!=par) { return findc(v,u); } } return u; } void caldis(int u,int par,int h) { res+=h*2; a.pb(u); for(int v:g[u]) { if(v!=par) caldis(v,u,h+1); } } void kfph() { cin >> n; for(int i=1;i<n;i++) { int u,v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } dfs(1,-1); cen=findc(1,-1); caldis(cen,-1,0); for(int i=0;i<n;i++) { ans[a[i]-1]=a[(i+n/2)%n]; } cout << res<< '\n'; for(int i=0;i<n;i++) { cout << ans[i] << ' '; } } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if(fopen(tdk".inp","r")) { freopen(tdk".inp","r",stdin); freopen(tdk".out","w",stdout); } int t=1; //cin >> t; while(t--) { kfph(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Village.cpp: In function 'int main()':
Village.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(tdk".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Village.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         freopen(tdk".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...