Submission #1834241


Source Code Expand

// 修改自提交记录:192182
// 原记录作者:E.Space (UID: 1579)
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
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*10+ch-'0';
		return F?n:-n;
	}
}
int fa[222222],siz[222222],pno,f[222222];
long long add[222222];
int gf(int u)
{
	if(fa[u]==u)return u;
	return fa[u]=gf(fa[u]);
}
struct edg
{
	int x,y,l;
}ed[555555];
bool operator <(const edg &x,const edg &y)
{
	return x.l>y.l;
}
int main()
{
//	freopen("migrate.in","r",stdin);
//	freopen("migrate.out","w",stdout);
	int n=io::F(),m=n-1;
	for(register int i=1;i<=m;++i)
		ed[i]=(edg){io::F(),io::F(),io::F()};
	std::sort(ed+1,ed+m+1);
	pno=n;
	for(register int i=1;i<=n;++i)fa[i]=i,siz[i]=1;
	for(register int i=1;i<=m;++i)
	{
		int t1=gf(ed[i].x),t2=gf(ed[i].y);
		if(t1==t2)continue;
		add[t1]=siz[t2]*(long long)ed[i].l;
		add[t2]=siz[t1]*(long long)ed[i].l;
		f[t1]=f[t2]=fa[t1]=fa[t2]=++pno;
		siz[pno]=siz[t1]+siz[t2];
		fa[pno]=pno;
	}
	for(register int i=pno-1;i;--i)
		add[i]+=add[f[i]];
	for(register int i=1;i<=n;++i)
		printf("%lld\n",add[i]);
	return 0;
}

Submission Info

Submission Time
Task E - Black Cats Deployment
User ESpace
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1461 Byte
Status AC
Exec Time 44 ms
Memory 7424 KB

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 200 / 200 200 / 200 400 / 400
Status
AC × 3
AC × 10
AC × 9
AC × 32
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt
Subtask2 00_example_02.txt, s1_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s3_15.txt, s3_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s3_27.txt, s3_28.txt, s3_29.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 2 ms 4224 KB
00_example_02.txt AC 1 ms 4224 KB
00_example_03.txt AC 2 ms 4224 KB
s1_01.txt AC 2 ms 4224 KB
s1_02.txt AC 2 ms 4224 KB
s1_03.txt AC 2 ms 4224 KB
s1_04.txt AC 2 ms 4224 KB
s1_05.txt AC 2 ms 4224 KB
s1_06.txt AC 2 ms 4224 KB
s1_07.txt AC 1 ms 2176 KB
s2_08.txt AC 27 ms 6272 KB
s2_09.txt AC 13 ms 5120 KB
s2_10.txt AC 9 ms 4736 KB
s2_11.txt AC 32 ms 6656 KB
s2_12.txt AC 31 ms 6656 KB
s2_13.txt AC 29 ms 6656 KB
s2_14.txt AC 27 ms 6656 KB
s3_15.txt AC 38 ms 6912 KB
s3_16.txt AC 19 ms 5376 KB
s3_17.txt AC 12 ms 4864 KB
s3_18.txt AC 19 ms 5504 KB
s3_19.txt AC 44 ms 7296 KB
s3_20.txt AC 43 ms 7296 KB
s3_21.txt AC 44 ms 7424 KB
s3_22.txt AC 44 ms 7424 KB
s3_23.txt AC 41 ms 7168 KB
s3_24.txt AC 36 ms 7168 KB
s3_25.txt AC 40 ms 7424 KB
s3_26.txt AC 35 ms 7168 KB
s3_27.txt AC 40 ms 7424 KB
s3_28.txt AC 35 ms 7168 KB
s3_29.txt AC 39 ms 7424 KB