結果

問題 No.872 All Tree Path
ユーザー tailstails
提出日時 2021-12-27 15:42:47
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 24 ms / 3,000 ms
コード長 1,204 bytes
コンパイル時間 1,098 ms
コンパイル使用メモリ 33,324 KB
実行使用メモリ 18,396 KB
最終ジャッジ日時 2023-10-26 01:16:05
合計ジャッジ時間 3,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,900 KB
testcase_01 AC 24 ms
9,900 KB
testcase_02 AC 24 ms
9,908 KB
testcase_03 AC 16 ms
18,396 KB
testcase_04 AC 2 ms
5,600 KB
testcase_05 AC 24 ms
9,864 KB
testcase_06 AC 24 ms
9,868 KB
testcase_07 AC 24 ms
9,868 KB
testcase_08 AC 3 ms
6,040 KB
testcase_09 AC 3 ms
6,044 KB
testcase_10 AC 3 ms
6,040 KB
testcase_11 AC 3 ms
6,044 KB
testcase_12 AC 3 ms
6,040 KB
testcase_13 AC 2 ms
5,600 KB
testcase_14 AC 1 ms
5,600 KB
testcase_15 AC 2 ms
5,600 KB
testcase_16 AC 2 ms
5,600 KB
testcase_17 AC 2 ms
5,600 KB
testcase_18 AC 1 ms
5,600 KB
testcase_19 AC 2 ms
5,600 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'f1':
main.c:65:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   65 |         write(1,wp,wbuf+sizeof wbuf-wp);
      |         ^~~~~
main.c:66:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   66 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

#define rd_skip() while(*rp++>=48)
#define rd_skip_line() while(*rp++!=10)
#define rd(v) long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define wt(v) {ulong _z=v;do*--wp=_z%10+48;while(_z/=10);}

typedef unsigned long ulong;
char*mmap();

#define MAXV 200000
#define MAXE 200000
int en[MAXV+1];
int ei[MAXV+1];
int eb[MAXE<<1];
char ew[MAXE<<1];
int uv[MAXE<<1];
char uw[MAXE];

long nv;
long z;

long g1(int i,int p){
	long nc=1;
	for(int k=0;k<en[i];++k){
		int j=eb[ei[i]+k];
		int c=ew[ei[i]+k];
		if(j!=p){
			long y=g1(j,i);
			z+=y*(nv-y)*c;
			nc+=y;
		}
	}
	return nc;
}

void graph_read(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	{ rd(t); nv=t; }
	for(int j=0;j<nv-1;++j){
		{ rd(t); uv[j<<1|0]=t; ++ei[t]; }
		{ rd(t); uv[j<<1|1]=t; ++ei[t]; }
		{ rd(t); uw[j]=t; }
	}
	{
		int s=0;
		for(int i=0;++i<=nv;){
			int t=s;
			s+=ei[i];
			ei[i]=t;
		}
	}
	for(int j=0;j<nv-1<<1;++j){
		int i=uv[j];
		int k=ei[i]+en[i]++;
		eb[k]=uv[j^1];
		ew[k]=uw[j>>1];
	}
}

void f1(long z){
	char wbuf[64],*wp=wbuf+sizeof wbuf;
	wt(z);
	write(1,wp,wbuf+sizeof wbuf-wp);
	_exit(0);
}

int main(){
	graph_read();
	g1(1,1);
	f1(z<<1);
	return 0;
}
0