結果
問題 | No.872 All Tree Path |
ユーザー |
|
提出日時 | 2021-04-06 01:00:38 |
言語 | Kuin (KuinC++ v.2021.9.17) |
結果 |
AC
|
実行時間 | 531 ms / 3,000 ms |
コード長 | 1,074 bytes |
コンパイル時間 | 2,695 ms |
コンパイル使用メモリ | 150,400 KB |
実行使用メモリ | 77,184 KB |
最終ジャッジ日時 | 2024-09-16 12:26:35 |
合計ジャッジ時間 | 8,101 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
func main()class Node()+var children: list<Node>+var size: int*func ctor()do me.children :: #list<Node>end func+func update(parent: Node)do me.children.head()for i(0, ^me.children - 1)var child: Node :: me.children.get()if(child <>& parent)do child.update(me)do me.size :+ child.sizeend ifdo me.children.next()end fordo me.size :+ 1end funcend classvar n: int :: cui@inputInt()var nodes: []Node :: #[n]Nodefor i(0, n - 1)do nodes[i] :: #Nodeend forvar u: []int :: #[n - 1]intvar v: []int :: #[n - 1]intvar w: []int :: #[n - 1]intfor i(0, n - 2)do u[i] :: cui@inputInt() - 1do v[i] :: cui@inputInt() - 1do w[i] :: cui@inputInt()do nodes[u[i]].children.add(nodes[v[i]])do nodes[v[i]].children.add(nodes[u[i]])end fordo nodes[0].update(null)var ans: int :: 0for i(0, n - 2)var size1: int :: [nodes[u[i]].size, nodes[v[i]].size].min()var size2: int :: n - size1do ans :+ size1 * size2 * w[i]end fordo ans :* 2do cui@print("\{ans}\n")end func