結果

問題 No.1103 Directed Length Sum
ユーザー marroncastlemarroncastle
提出日時 2020-07-25 19:24:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,670 ms / 3,000 ms
コード長 428 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 277,452 KB
最終ジャッジ日時 2023-09-09 20:59:42
合計ジャッジ時間 17,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,660 KB
testcase_01 AC 89 ms
71,536 KB
testcase_02 AC 868 ms
195,920 KB
testcase_03 AC 802 ms
277,452 KB
testcase_04 AC 968 ms
140,188 KB
testcase_05 AC 1,670 ms
197,772 KB
testcase_06 AC 650 ms
115,412 KB
testcase_07 AC 233 ms
85,172 KB
testcase_08 AC 306 ms
90,556 KB
testcase_09 AC 190 ms
82,868 KB
testcase_10 AC 386 ms
95,988 KB
testcase_11 AC 1,046 ms
146,680 KB
testcase_12 AC 648 ms
115,100 KB
testcase_13 AC 385 ms
96,496 KB
testcase_14 AC 171 ms
82,500 KB
testcase_15 AC 528 ms
105,460 KB
testcase_16 AC 1,175 ms
157,724 KB
testcase_17 AC 1,216 ms
160,508 KB
testcase_18 AC 379 ms
95,664 KB
testcase_19 AC 1,065 ms
150,808 KB
testcase_20 AC 206 ms
84,256 KB
testcase_21 AC 281 ms
88,600 KB
testcase_22 AC 880 ms
133,484 KB
testcase_23 AC 574 ms
109,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
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