結果

問題 No.1098 LCAs
ユーザー tailstails
提出日時 2020-11-04 17:55:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 29,900 KB
実行使用メモリ 24,988 KB
最終ジャッジ日時 2023-09-29 15:49:16
合計ジャッジ時間 6,054 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,496 KB
testcase_01 AC 1 ms
5,524 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
5,492 KB
testcase_04 AC 1 ms
5,576 KB
testcase_05 AC 2 ms
5,584 KB
testcase_06 AC 1 ms
5,568 KB
testcase_07 AC 2 ms
5,488 KB
testcase_08 AC 1 ms
5,588 KB
testcase_09 AC 1 ms
5,564 KB
testcase_10 AC 2 ms
5,496 KB
testcase_11 AC 1 ms
5,556 KB
testcase_12 AC 2 ms
5,628 KB
testcase_13 AC 1 ms
5,588 KB
testcase_14 AC 1 ms
5,508 KB
testcase_15 AC 1 ms
5,444 KB
testcase_16 AC 1 ms
5,540 KB
testcase_17 AC 1 ms
5,592 KB
testcase_18 AC 22 ms
10,448 KB
testcase_19 AC 23 ms
10,452 KB
testcase_20 AC 22 ms
10,472 KB
testcase_21 AC 22 ms
10,456 KB
testcase_22 AC 22 ms
10,392 KB
testcase_23 AC 14 ms
9,664 KB
testcase_24 AC 15 ms
9,648 KB
testcase_25 AC 13 ms
9,596 KB
testcase_26 AC 14 ms
10,476 KB
testcase_27 AC 13 ms
10,232 KB
testcase_28 AC 44 ms
23,976 KB
testcase_29 AC 45 ms
24,988 KB
testcase_30 AC 43 ms
23,908 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:38:1: 警告: 戻り値の型をデフォルトの ‘int’ にします [-Wimplicit-int]
   38 | main(){
      | ^~~~
main.c: 関数 ‘main’ 内:
main.c:72:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   72 |         write(1,wp,(wbuf+sizeof wbuf)-wp);
      |         ^~~~~
main.c:73:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   73 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

char*mmap();
#define RD(v) int v=0;{int c;while(c=*rp++-48,c>=0)v=v*10+c;}

char wbuf[20*200000];

#define MAXN 200000
int en[MAXN+1];
int ei[MAXN+1];
int eb[MAXN<<1];
union{
	int uv[MAXN<<1];
	struct{
		int ss1[MAXN+1];
		long ss2[MAXN+1];
	};
}u;
#define uv  u.uv
#define ss1 u.ss1
#define ss2 u.ss2

void f(int i,int p){
	ss1[i]=1;
	ss2[i]=0;
	for(int k=0;k<en[i];++k){
		int j=eb[ei[i]+k];
		if(j!=p){
			f(j,i);
			ss1[i]+=ss1[j];
			ss2[i]+=(long)ss1[j]*ss1[j];
		}
	}
	ss2[i]=(long)ss1[i]*ss1[i]-ss2[i];
}

main(){
	char*rp=mmap(0l,7l*400001,1,2,0,0ll);
	RD(n);
	{
		int ne=n-1<<1;
		for(int j=0;j<ne;++j){
			RD(t);
			uv[j]=t;
			++en[uv[j]];
		}
	}
	{
		int s=0;
		for(int i=0;++i<=n;){
			ei[i]=s;
			s+=en[i];
			en[i]=0;
		}
	}
	{
		int ne=n-1<<1;
		for(int j=0;j<ne;++j){
			int i=uv[j];
			eb[ei[i]+en[i]++]=uv[j^1];
		}
	}

	f(1,0);
	char*wp=wbuf+sizeof wbuf;
	for(int i=n+1;--i;){
		long z=ss2[i];
		*--wp=10;
		while(*--wp=z%10+48,z/=10);
	}
	write(1,wp,(wbuf+sizeof wbuf)-wp);
	_exit(0);
}
0