Submission #2123686


Source Code Expand

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
struct edge
{
	int to;
	int next;
}e[333333];
int pe=111111;
int deg[111111];
void insert(int a,int to)
{
	e[pe]=(edge){to,e[a].next};
	e[a].next=pe++;
	deg[to]++;
}
int f[111111],g[111111];
void dfs(int o,int fa)
{
	if(deg[o]==1){g[o]=1;return;}
	for(register int p=e[o].next;p;p=e[p].next)
		if(e[p].to!=fa)
		{
			dfs(e[p].to,o);
			if(g[e[p].to])++g[o];
				else f[o]+=f[e[p].to];
		}
	if(g[o]>1)f[o]+=g[o]-1,g[o]=0;
		else if(g[o]==1&&deg[o]-(o!=fa)!=1)g[o]=0;
}
int main()
{
	int n=io::F();
	for(register int i=1;i<n;++i)
	{
		int x=io::F(),y=io::F();
		insert(x,y);
		insert(y,x);
	}
	for(register int i=0;i<n;++i)
		if(deg[i]>2){dfs(i,i);printf("%d\n",f[i]);return 0;}
	puts("1");
	return 0;
}

Submission Info

Submission Time
Task E - Antennas on Tree
User ESpace
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1477 Byte
Status AC
Exec Time 19 ms
Memory 6144 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 128 KB
0_01.txt AC 1 ms 128 KB
0_02.txt AC 1 ms 128 KB
1_00.txt AC 1 ms 128 KB
1_01.txt AC 1 ms 128 KB
1_02.txt AC 1 ms 128 KB
1_03.txt AC 1 ms 128 KB
1_04.txt AC 1 ms 128 KB
1_05.txt AC 1 ms 128 KB
1_06.txt AC 12 ms 2944 KB
1_07.txt AC 12 ms 3328 KB
1_08.txt AC 12 ms 2944 KB
1_09.txt AC 12 ms 3328 KB
1_10.txt AC 19 ms 6144 KB
1_11.txt AC 19 ms 4864 KB
1_12.txt AC 18 ms 3840 KB
1_13.txt AC 18 ms 3712 KB
1_14.txt AC 18 ms 3712 KB
1_15.txt AC 17 ms 3712 KB
1_16.txt AC 17 ms 3712 KB
1_17.txt AC 17 ms 3712 KB
1_18.txt AC 15 ms 3584 KB
1_19.txt AC 14 ms 3584 KB
1_20.txt AC 14 ms 3584 KB
1_21.txt AC 13 ms 3456 KB
1_22.txt AC 13 ms 3328 KB