結果
問題 | No.872 All Tree Path |
ユーザー |
|
提出日時 | 2021-04-05 20:08:46 |
言語 | Kuin (KuinC++ v.2021.9.17) |
結果 |
AC
|
実行時間 | 556 ms / 3,000 ms |
コード長 | 1,205 bytes |
コンパイル時間 | 3,065 ms |
コンパイル使用メモリ | 150,336 KB |
実行使用メモリ | 77,056 KB |
最終ジャッジ日時 | 2024-09-16 12:24:57 |
合計ジャッジ時間 | 9,288 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
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