結果

問題 No.901 K-ary εxtrεεmε
ユーザー tailstails
提出日時 2022-10-21 15:44:57
言語 cLay
(20240104-1)
結果
AC  
実行時間 58 ms / 3,000 ms
コード長 459 bytes
コンパイル時間 7,224 ms
コンパイル使用メモリ 209,152 KB
実行使用メモリ 16,888 KB
最終ジャッジ日時 2023-09-13 16:47:24
合計ジャッジ時間 12,538 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
16,500 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 52 ms
16,344 KB
testcase_08 AC 53 ms
16,548 KB
testcase_09 AC 55 ms
16,376 KB
testcase_10 AC 54 ms
16,420 KB
testcase_11 AC 54 ms
16,368 KB
testcase_12 AC 56 ms
16,480 KB
testcase_13 AC 58 ms
16,352 KB
testcase_14 AC 57 ms
16,292 KB
testcase_15 AC 57 ms
16,412 KB
testcase_16 AC 57 ms
16,332 KB
testcase_17 AC 52 ms
16,632 KB
testcase_18 AC 53 ms
16,888 KB
testcase_19 AC 52 ms
16,696 KB
testcase_20 AC 53 ms
16,708 KB
testcase_21 AC 52 ms
16,624 KB
testcase_22 AC 54 ms
16,380 KB
testcase_23 AC 51 ms
16,376 KB
testcase_24 AC 53 ms
16,420 KB
testcase_25 AC 51 ms
16,556 KB
testcase_26 AC 51 ms
16,372 KB
testcase_27 AC 43 ms
16,516 KB
testcase_28 AC 44 ms
16,460 KB
testcase_29 AC 42 ms
16,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ll@n;
int u[n],v[],w[];
rd((u,v,w)(n-1));
wgraph<int>g;
g.setEdge(n,n-1,u,v,w);
ll d[n];
g.getDistForest(0,d);
HLD h;
h.init(g.g);
int o[n],p[];
g.g.preorder(p);
rep(i,n)o[p[i]]=i;
ll@q;
rep(q){
	ll@k;
	ull x[k];
	rep(i,k){
		int@xi;
		x[i]=xi|(ull)o[xi]<<32;
	}
	sortA(k,x);
	int a=x[0],b=a;
	ll z=0;
	rep(i,1,k){
		int c=x[i];
		int e=h.lca(a,c);
		if(a==e){
			e=h.lca(b,c);
			z+=d[c]-d[e];
		}else{
			z+=d[a]+d[c]-2d[e];
			a=e;
		}
		b=c;
	}
	wt(z);
}
0