# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940365 | 2024-03-07T08:36:25 Z | pcc | Village (BOI20_village) | C++14 | 2 ms | 4440 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 4184 KB | Partially correct |
2 | Partially correct | 1 ms | 4188 KB | Partially correct |
3 | Partially correct | 1 ms | 4184 KB | Partially correct |
4 | Partially correct | 1 ms | 4188 KB | Partially correct |
5 | Partially correct | 1 ms | 4192 KB | Partially correct |
6 | Partially correct | 2 ms | 4188 KB | Partially correct |
7 | Incorrect | 1 ms | 4188 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Partially correct | 1 ms | 4184 KB | Partially correct |
2 | Partially correct | 1 ms | 4188 KB | Partially correct |
3 | Partially correct | 1 ms | 4184 KB | Partially correct |
4 | Partially correct | 1 ms | 4188 KB | Partially correct |
5 | Partially correct | 1 ms | 4192 KB | Partially correct |
6 | Partially correct | 2 ms | 4188 KB | Partially correct |
7 | Incorrect | 1 ms | 4188 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |