結果

問題 No.1103 Directed Length Sum
ユーザー 👑 tatt61880tatt61880
提出日時 2021-04-06 00:52:20
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 2,487 ms / 3,000 ms
コード長 1,091 bytes
コンパイル時間 3,081 ms
コンパイル使用メモリ 167,832 KB
実行使用メモリ 315,860 KB
最終ジャッジ日時 2023-10-14 18:21:18
合計ジャッジ時間 24,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1,302 ms
315,860 KB
testcase_03 AC 1,006 ms
222,188 KB
testcase_04 AC 1,324 ms
126,892 KB
testcase_05 AC 2,487 ms
216,704 KB
testcase_06 AC 807 ms
83,640 KB
testcase_07 AC 161 ms
22,928 KB
testcase_08 AC 261 ms
33,092 KB
testcase_09 AC 95 ms
15,832 KB
testcase_10 AC 376 ms
43,948 KB
testcase_11 AC 1,450 ms
137,840 KB
testcase_12 AC 811 ms
84,460 KB
testcase_13 AC 383 ms
45,084 KB
testcase_14 AC 70 ms
12,636 KB
testcase_15 AC 598 ms
66,552 KB
testcase_16 AC 1,671 ms
154,436 KB
testcase_17 AC 1,754 ms
161,032 KB
testcase_18 AC 373 ms
43,572 KB
testcase_19 AC 1,527 ms
141,076 KB
testcase_20 AC 118 ms
18,108 KB
testcase_21 AC 236 ms
30,348 KB
testcase_22 AC 1,201 ms
116,088 KB
testcase_23 AC 649 ms
71,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	const mod: int :: 1000000007
	class Node()
		+var parent: Node
		+var children: list<Node>
		+var depth: int
		+var size: int
		*func ctor()
			do me.parent :: null
			do me.children :: #list<Node>
		end func
		+func update()
			if(me.parent <>& null)
				do me.depth :: me.parent.depth + 1
			end if
			do me.children.head()
			for i(0, ^me.children - 1)
				var child: Node :: me.children.get()
				do child.update()
				do me.size :+ child.size
				do me.children.next()
			end for
			do me.size :+ 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
	for i(0, n - 2)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		do nodes[a].children.add(nodes[b])
		do nodes[b].parent :: nodes[a]
	end for
	var root: Node
	for i(0, n - 1)
		if(nodes[i].parent =& null)
			do root :: nodes[i]
			break i
		end if
	end for
	do root.update()
	
	var ans: int :: 0
	for i(0, n - 1)
		do ans :+ nodes[i].depth * nodes[i].size
		do ans :% mod
	end for
	do cui@print("\{ans}\n")
end func
0