結果

問題 No.872 All Tree Path
ユーザー 👑 tatt61880tatt61880
提出日時 2021-04-05 20:08:46
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 565 ms / 3,000 ms
コード長 1,205 bytes
コンパイル時間 3,158 ms
コンパイル使用メモリ 171,080 KB
実行使用メモリ 77,004 KB
最終ジャッジ日時 2023-10-14 18:18:21
合計ジャッジ時間 10,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 560 ms
58,360 KB
testcase_01 AC 552 ms
58,204 KB
testcase_02 AC 555 ms
58,332 KB
testcase_03 AC 353 ms
77,004 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 565 ms
58,340 KB
testcase_06 AC 549 ms
58,384 KB
testcase_07 AC 558 ms
58,408 KB
testcase_08 AC 44 ms
8,972 KB
testcase_09 AC 45 ms
9,084 KB
testcase_10 AC 44 ms
8,976 KB
testcase_11 AC 44 ms
9,112 KB
testcase_12 AC 45 ms
9,060 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	class Node()
		+var parent: Node
		+var children: list<Node>
		+var num: int
		*func ctor()
			do me.children :: #list<Node>
		end func
		+func calcNum()
			do me.children.head()
			for i(0, ^me.children - 1)
				var child: Node :: me.children.get()
				if(child.parent =& null)
					do child.parent :: me
					do child.calcNum()
					do me.num :+ child.num
				end if
				do me.children.next()
			end for
			do me.num :+ 1
		end func
	end class
	
	var n: int :: cui@inputInt()
	var nodes: []Node :: #[n]Node
	for i(0, n - 1)
		do nodes[i] :: #Node
	end for
	var u: []int :: #[n - 1]int
	var v: []int :: #[n - 1]int
	var w: []int :: #[n - 1]int
	for i(0, n - 2)
		do u[i] :: cui@inputInt() - 1
		do v[i] :: cui@inputInt() - 1
		do w[i] :: cui@inputInt()
		do nodes[u[i]].children.add(nodes[v[i]])
		do nodes[v[i]].children.add(nodes[u[i]])
	end for
	
	do nodes[0].parent :: nodes[0]
	do nodes[0].calcNum()
	
	var ans: int :: 0
	for i(0, n - 2)
		var num1: int
		if(nodes[u[i]].parent =& nodes[v[i]])
			do num1 :: nodes[u[i]].num
		else
			do num1 :: nodes[v[i]].num
		end if
		var num2: int :: n - num1
		do ans :+ num1 * num2 * w[i]
	end for
	do ans :* 2
	do cui@print("\{ans}\n")
end func
0