結果

問題 No.1103 Directed Length Sum
ユーザー marroncastlemarroncastle
提出日時 2020-07-25 19:26:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 466 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 212,568 KB
最終ジャッジ日時 2023-09-09 21:02:14
合計ジャッジ時間 13,195 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,692 KB
testcase_01 AC 17 ms
8,652 KB
testcase_02 AC 2,516 ms
149,644 KB
testcase_03 AC 2,811 ms
212,568 KB
testcase_04 AC 2,157 ms
85,488 KB
testcase_05 TLE -
testcase_06 AC 1,359 ms
58,864 KB
testcase_07 AC 271 ms
20,620 KB
testcase_08 AC 419 ms
26,804 KB
testcase_09 AC 166 ms
16,160 KB
testcase_10 AC 601 ms
33,900 KB
testcase_11 AC 2,420 ms
91,816 KB
testcase_12 AC 1,301 ms
58,836 KB
testcase_13 AC 641 ms
34,576 KB
testcase_14 AC 122 ms
14,432 KB
testcase_15 AC 956 ms
47,836 KB
testcase_16 AC 2,702 ms
102,672 KB
testcase_17 AC 2,832 ms
106,532 KB
testcase_18 AC 573 ms
33,632 KB
testcase_19 AC 2,475 ms
94,448 KB
testcase_20 AC 189 ms
17,884 KB
testcase_21 AC 360 ms
25,272 KB
testcase_22 AC 1,971 ms
78,788 KB
testcase_23 AC 1,057 ms
50,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
edge = [[] for _ in range(N)]
roots = [True]*N
for _ in range(N-1):
    a,b = map(int, input().split())
    roots[b-1] = False
    edge[a-1].append(b-1)

ans = 0
mod = 10**9+7
d = deque()
root = roots.index(True)
d.append([root,0])
while len(d)>0:
    v,depth = d.popleft()
    ans += depth*(depth+1)//2
    ans %= mod
    for w in edge[v]:
        d.append([w,depth+1])
print(ans)
0