結果

問題 No.1103 Directed Length Sum
ユーザー Ldio03Ldio03
提出日時 2020-07-04 00:40:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 596 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 11,848 KB
実行使用メモリ 306,712 KB
最終ジャッジ日時 2023-10-17 06:43:44
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from collections import deque
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
depth=[-1]*N
forward, back = 0, 1
root = parent.index(None)
ans = 0
pool = deque([root])
depth[root]=0
while pool:
    node = pool.popleft()
    ans += depth[node] * (depth[node]+1) // 2
    ans %= MOD
    for c in children[node]:
        if depth[c]!=-1:continue
        depth[c]=depth[node]+1
        pool.append(c)

print(ans)
0