結果

問題 No.872 All Tree Path
ユーザー 👑 tatt61880tatt61880
提出日時 2021-04-05 20:06:07
言語 Kuin
(KuinC++ v.2021.9.17)
結果
WA  
実行時間 -
コード長 1,278 bytes
コンパイル時間 2,737 ms
コンパイル使用メモリ 170,480 KB
実行使用メモリ 77,192 KB
最終ジャッジ日時 2023-10-14 18:19:34
合計ジャッジ時間 8,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,352 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	const mod: int :: 1000000007
	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 % mod * w[i] % mod
		do ans :% mod
	end for
	do ans :* 2
	do ans :% mod
	do cui@print("\{ans}\n")
end func
0