Submission #940158

#TimeUsernameProblemLanguageResultExecution timeMemory
940158pccVillage (BOI20_village)C++14
0 / 100
1 ms4444 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]; int dep[mxn]; void dfs(int now,int par){ vector<int> need; dp[now] = 1; for(auto nxt:tree[now]){ if(nxt == par)continue; dep[nxt] = dep[now]+1; 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++){ if(mx[i]<i)ansv.push_back({mx[i],i}); } return; } } namespace S2{ vector<pii> ansv; int mx[mxn]; ll ans; void solve(){ } } 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(auto &i:S1::ansv)cout<<i.fs<<' ';cout<<'\n'; for(auto &i:S1::ansv)cout<<i.sc<<' ';cout<<'\n'; for(auto &i:S2::ansv)cout<<i.fs<<' ';cout<<'\n'; for(auto &i:S2::ansv)cout<<i.sc<<' ';cout<<'\n'; return 0; }

Compilation message (stderr)

Village.cpp: In function 'int main()':
Village.cpp:102:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  102 |  for(auto &i:S1::ansv)cout<<i.fs<<' ';cout<<'\n';
      |  ^~~
Village.cpp:102:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  102 |  for(auto &i:S1::ansv)cout<<i.fs<<' ';cout<<'\n';
      |                                       ^~~~
Village.cpp:103:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  103 |  for(auto &i:S1::ansv)cout<<i.sc<<' ';cout<<'\n';
      |  ^~~
Village.cpp:103:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  103 |  for(auto &i:S1::ansv)cout<<i.sc<<' ';cout<<'\n';
      |                                       ^~~~
Village.cpp:104:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  104 |  for(auto &i:S2::ansv)cout<<i.fs<<' ';cout<<'\n';
      |  ^~~
Village.cpp:104:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  104 |  for(auto &i:S2::ansv)cout<<i.fs<<' ';cout<<'\n';
      |                                       ^~~~
Village.cpp:105:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  105 |  for(auto &i:S2::ansv)cout<<i.sc<<' ';cout<<'\n';
      |  ^~~
Village.cpp:105:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  105 |  for(auto &i:S2::ansv)cout<<i.sc<<' ';cout<<'\n';
      |                                       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...