Submission #60986670
Source Code Expand
Copy
#include<bits/stdc++.h>using namespace std;namespace SOLUTION{const int maxn=3e5+5;vector<int>e[maxn];int fa[maxn],siz[maxn];inline void prework(int u,int father){fa[u]=father;siz[u]=1;for(int v:e[u]){if(v!=father){prework(v,u);++siz[u];}}}int ans=0;int vec[maxn];inline void dfs(int u){int cnt=0;for(int v:e[u]){
#include<bits/stdc++.h> using namespace std; namespace SOLUTION{ const int maxn=3e5+5; vector<int>e[maxn]; int fa[maxn],siz[maxn]; inline void prework(int u,int father){ fa[u]=father; siz[u]=1; for(int v:e[u]){ if(v!=father){ prework(v,u); ++siz[u]; } } } int ans=0; int vec[maxn]; inline void dfs(int u){ int cnt=0; for(int v:e[u]){ vec[++cnt]=siz[v]; } sort(vec+1,vec+cnt+1); for(int i=1;i<=cnt;++i){ if(vec[i]>=2){ ans=max(ans,1+(cnt-i+1)*vec[i]); } } for(int v:e[u]){ if(v!=fa[u]){ --siz[u],++siz[v]; dfs(v); ++siz[u],--siz[v]; } } } inline int Main(){ int n; cin>>n; for(int i=1;i<n;++i){ int u,v; cin>>u>>v; e[u].push_back(v); e[v].push_back(u); } prework(1,0); dfs(1); cout<<n-ans<<"\n"; return 0; } } int main(){ //freopen(".in","r",stdin); //freopen(".out","w",stdout); ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); SOLUTION::Main(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Snowflake Tree |
User | sangshang |
Language | C++ 20 (gcc 12.2) |
Score | 450 |
Code Size | 1029 Byte |
Status | AC |
Exec Time | 106 ms |
Memory | 46816 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 450 / 450 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 2 ms | 3524 KB |
00_sample_02.txt | AC | 2 ms | 3444 KB |
00_sample_03.txt | AC | 2 ms | 3476 KB |
01_random_01.txt | AC | 106 ms | 22584 KB |
01_random_02.txt | AC | 54 ms | 14360 KB |
01_random_03.txt | AC | 100 ms | 22572 KB |
01_random_04.txt | AC | 39 ms | 11356 KB |
01_random_05.txt | AC | 104 ms | 22492 KB |
01_random_06.txt | AC | 10 ms | 5616 KB |
01_random_07.txt | AC | 100 ms | 22592 KB |
01_random_08.txt | AC | 51 ms | 13316 KB |
01_random_09.txt | AC | 105 ms | 22664 KB |
01_random_10.txt | AC | 82 ms | 19548 KB |
01_random_11.txt | AC | 87 ms | 22708 KB |
01_random_12.txt | AC | 76 ms | 19396 KB |
01_random_13.txt | AC | 85 ms | 22868 KB |
01_random_14.txt | AC | 75 ms | 19196 KB |
01_random_15.txt | AC | 96 ms | 22576 KB |
01_random_16.txt | AC | 59 ms | 19468 KB |
01_random_17.txt | AC | 71 ms | 23404 KB |
01_random_18.txt | AC | 75 ms | 20832 KB |
01_random_19.txt | AC | 95 ms | 22568 KB |
01_random_20.txt | AC | 64 ms | 18032 KB |
02_handmade_01.txt | AC | 70 ms | 24340 KB |
02_handmade_02.txt | AC | 75 ms | 22844 KB |
02_handmade_03.txt | AC | 71 ms | 24196 KB |
02_handmade_04.txt | AC | 79 ms | 24204 KB |
02_handmade_05.txt | AC | 105 ms | 46816 KB |
02_handmade_06.txt | AC | 76 ms | 22320 KB |