結果

問題 No.1103 Directed Length Sum
ユーザー AtamaokaCAtamaokaC
提出日時 2020-07-03 21:34:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,188 ms / 3,000 ms
コード長 459 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 378,896 KB
最終ジャッジ日時 2023-10-16 23:23:39
合計ジャッジ時間 20,210 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,616 KB
testcase_01 AC 34 ms
53,616 KB
testcase_02 AC 1,392 ms
378,896 KB
testcase_03 AC 957 ms
275,728 KB
testcase_04 AC 1,184 ms
181,392 KB
testcase_05 AC 2,188 ms
256,052 KB
testcase_06 AC 790 ms
144,920 KB
testcase_07 AC 208 ms
92,448 KB
testcase_08 AC 299 ms
101,364 KB
testcase_09 AC 154 ms
86,412 KB
testcase_10 AC 414 ms
111,576 KB
testcase_11 AC 1,326 ms
190,724 KB
testcase_12 AC 779 ms
145,604 KB
testcase_13 AC 404 ms
112,248 KB
testcase_14 AC 132 ms
83,620 KB
testcase_15 AC 621 ms
130,572 KB
testcase_16 AC 1,491 ms
204,464 KB
testcase_17 AC 1,621 ms
209,740 KB
testcase_18 AC 403 ms
111,040 KB
testcase_19 AC 1,391 ms
193,492 KB
testcase_20 AC 176 ms
88,876 KB
testcase_21 AC 283 ms
99,152 KB
testcase_22 AC 1,079 ms
172,632 KB
testcase_23 AC 633 ms
134,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7
inpl = lambda: list(map(int,input().split()))
N = int(input())
children = [set() for _ in range(N)]
parent = [None] * N
for _ in range(N-1):
    A, B = inpl()
    A, B = A-1, B-1
    children[A].add(B)
    parent[B] = A

forward, back = 0, 1
root = parent.index(None)
ans = 0
pool = [(root,0)]
while pool:
    node, d = pool.pop()
    ans += d * (d+1) // 2
    ans %= MOD
    for c in children[node]:
        pool.append((c, d+1))

print(ans)
0