Submission #60975794


Source Code Expand

Copy
#include<bits/stdc++.h>
#define int long long
#define f(i,j,n) for(int i=j;i<=n;i++)
#define F(i,n,j) for(int i=n;i>=j;i--)
#define updmax(a,b) a=max(a,b)
#define updmin(a,b) a=min(a,b)
#define pb push_back
#define XQZ
using namespace std;
namespace fsd{
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin),p1==p2)?EOF:*p1++)
const int MAXSIZE=1<<20;
char buf[MAXSIZE],*p1,*p2;
inline int read(){
int ak=0,ioi=1;char c=gc();
while(!isdigit(c)){if(c=='-')ioi=-1;c=gc();}
while(isdigit(c))ak=ak*10+(c^48),c=gc();
return ak*ioi;
}
inline string reads(){
string o="";
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
#define int long long
#define f(i,j,n) for(int i=j;i<=n;i++)
#define F(i,n,j) for(int i=n;i>=j;i--)
#define updmax(a,b) a=max(a,b)
#define updmin(a,b) a=min(a,b)
#define pb push_back
#define XQZ
using namespace std;
namespace fsd{
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin),p1==p2)?EOF:*p1++)
	const int MAXSIZE=1<<20;
	char buf[MAXSIZE],*p1,*p2;
	inline int read(){
		int ak=0,ioi=1;char c=gc();
		while(!isdigit(c)){if(c=='-')ioi=-1;c=gc();}
		while(isdigit(c))ak=ak*10+(c^48),c=gc();
		return ak*ioi;
	}
	inline string reads(){
		string o="";
		char p=gc();
		while(p>'z'||p<'a'){p=gc();}
		while(p<='z'&&p>='a'){o+=p;p=gc();}
		return o;
	}
	inline char readc(){
		char p=gc();
		while(!((p<='z'&&p>='a')||(p<='Z'&&p>='A'))){p=gc();}
		return p;
	}
	inline long double readd(){
		long double ak=0;int ioi=1;char c=gc();
		while(!isdigit(c)){if(c=='-')ioi=-1;c=gc();}
		while(isdigit(c))ak*=10,ak+=c-'0',c=gc();
		c=gc();
		long double q=0.1;
		while(isdigit(c))ak+=(c-'0')*q,q*=0.1,c=gc();
		return ak*ioi;
	}
}
using namespace fsd;
const int N=3e5+10;
int n;
vector<int> h[N];
int downs[N];
int up2[N];
void dfs(int k,int prt){
	downs[k]=h[k].size()-!!prt;
	for(auto v:h[k]){
		if(v==prt)continue;
		dfs(v,k);
	}
}
int ans=0;
vector<int> uu;
void dfs1(int k,int prt,int upc){
	int sm=upc,minn=(prt?upc:LLONG_MAX/2);
	for(auto v:h[k]){
		if(v==prt)continue;
		dfs1(v,k,downs[k]+(!!prt));
		sm+=downs[v]+1;
		updmin(minn,downs[v]+1);
	}
	uu.clear();
	if(prt)uu.push_back(upc);
	for(auto v:h[k]){
		if(v==prt)continue;
		uu.push_back(downs[v]+1);
	}
	sort(uu.begin(),uu.end());
	int lv=downs[k]+!!prt;
	for(auto v:uu){
		updmax(ans,1+v*lv);
		lv--;
	}
}
void gs(){
	cin>>n;
	f(i,1,n-1){
		int p,q;cin>>p>>q;
		h[p].push_back(q);
		h[q].push_back(p);
	}
	dfs(1,0);
	dfs1(1,0,0);
	cout<<n-ans<<endl;
}
signed main(){
#ifndef XQZ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
#ifdef NXD
	int t=0;cin>>t;while(t--)
#endif
		gs();
	return 0;
}

Submission Info

Submission Time
Task E - Snowflake Tree
User xiangqizhen
Language C++ 17 (gcc 12.2)
Score 450
Code Size 2098 Byte
Status AC
Exec Time 272 ms
Memory 46984 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 29
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 4 ms 10524 KB
00_sample_02.txt AC 4 ms 10712 KB
00_sample_03.txt AC 4 ms 10712 KB
01_random_01.txt AC 272 ms 23996 KB
01_random_02.txt AC 132 ms 18220 KB
01_random_03.txt AC 258 ms 24256 KB
01_random_04.txt AC 84 ms 16144 KB
01_random_05.txt AC 269 ms 24068 KB
01_random_06.txt AC 21 ms 11972 KB
01_random_07.txt AC 268 ms 24028 KB
01_random_08.txt AC 122 ms 17524 KB
01_random_09.txt AC 264 ms 24116 KB
01_random_10.txt AC 206 ms 22144 KB
01_random_11.txt AC 219 ms 24152 KB
01_random_12.txt AC 201 ms 22124 KB
01_random_13.txt AC 212 ms 25436 KB
01_random_14.txt AC 205 ms 21816 KB
01_random_15.txt AC 245 ms 24000 KB
01_random_16.txt AC 141 ms 21760 KB
01_random_17.txt AC 180 ms 24464 KB
01_random_18.txt AC 213 ms 23132 KB
01_random_19.txt AC 255 ms 24056 KB
01_random_20.txt AC 135 ms 21440 KB
02_handmade_01.txt AC 179 ms 30292 KB
02_handmade_02.txt AC 175 ms 26172 KB
02_handmade_03.txt AC 173 ms 30328 KB
02_handmade_04.txt AC 169 ms 30336 KB
02_handmade_05.txt AC 259 ms 46984 KB
02_handmade_06.txt AC 197 ms 24580 KB


2025-03-05 (Wed)
18:13:42 +00:00