제출 #940214

#제출 시각아이디문제언어결과실행 시간메모리
940214pccVillage (BOI20_village)C++14
0 / 100
3 ms4188 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 1e5+10; vector<int> tree[mxn]; int N; namespace S1{ vector<pii> ansv; ll ans; ll dp[mxn]; int mx[mxn]; void dfs(int now,int par){ vector<int> need; dp[now] = 1; for(auto nxt:tree[now]){ if(nxt == par)continue; dfs(nxt,now); if(dp[nxt])need.push_back(nxt); } if(now == par){ dp[now] = 0; if(need.empty()){ ans += 2; int a = tree[now][0],b = mx[a]; mx[b] = now; mx[now] = a; } else if((need.size()+1)%2==0){ ans += 2; int a = need.back(); need.pop_back(); mx[a] = now; mx[now] = a; } else{ ans += 4; int a = need.back();need.pop_back(); int b = need.back();need.pop_back(); mx[a] = b; mx[b] = now; mx[now] = a; } } while(need.size()>=2){ ans += 4; int a = need.end()[-1],b = need.end()[-2]; need.pop_back(); need.pop_back(); mx[a] = b,mx[b] = a; } if(dp[now]&&!need.empty()){ ans += 2; int a = need.back(); need.pop_back(); dp[now] = 0; mx[now] = a; mx[a] = now; } return; } void solve(){ dfs(1,1); for(int i = 1;i<=N;i++){ ansv.push_back({i,mx[i]}); } return; } } namespace S2{ vector<pii> ansv; int mx[mxn]; ll ans; void solve(){ ansv = vector<pii>(N,pii(1,1)); } } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N; for(int i = 1;i<N;i++){ int a,b; cin>>a>>b; tree[a].push_back(b); tree[b].push_back(a); } S1::solve(); S2::solve(); cout<<S1::ans<<' '<<S2::ans<<'\n'; for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n'; for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n'; return 0; }

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

Village.cpp: In function 'int main()':
Village.cpp:100:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  100 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:100:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  100 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
Village.cpp:101:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  101 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:101:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  101 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...