Submission #940365

#TimeUsernameProblemLanguageResultExecution timeMemory
940365pccVillage (BOI20_village)C++14
0 / 100
2 ms4440 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{ 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(need.size()>=2){ dp[now] = 0; ans += need.size()*2; for(int i = 1;i<need.size();i++){ mx[need[i-1]] = need[i]; } mx[need.back()] = now; mx[now] = need[0]; need.clear(); } else if(need.size() == 1){ dp[now] = 0; ans += 2; int a = need[0]; mx[now] = a; mx[a] = now; } if(now==par&&dp[now]){ ans += 2; int a = tree[now][0],b = mx[a]; mx[b] = now,mx[now] = a; } return; } void solve(){ dfs(1,1); return; } } namespace S2{ 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(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; }

Compilation message (stderr)

Village.cpp: In function 'void S1::dfs(int, int)':
Village.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for(int i = 1;i<need.size();i++){
      |                  ~^~~~~~~~~~~~
Village.cpp: In function 'int main()':
Village.cpp:77:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   77 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:77:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   77 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |                                              ^~~~
Village.cpp:78:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   78 |  for(int i = 1;i<=N;i++)cout<<S1::mx[i]<<' ';cout<<'\n';
      |  ^~~
Village.cpp:78:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   78 |  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...