結果

問題 No.1103 Directed Length Sum
ユーザー marroncastlemarroncastle
提出日時 2020-07-25 19:25:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,404 ms / 3,000 ms
コード長 466 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 265,868 KB
最終ジャッジ日時 2023-09-09 21:01:16
合計ジャッジ時間 14,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,632 KB
testcase_01 AC 93 ms
71,864 KB
testcase_02 AC 576 ms
196,024 KB
testcase_03 AC 585 ms
265,868 KB
testcase_04 AC 820 ms
140,972 KB
testcase_05 AC 1,404 ms
197,580 KB
testcase_06 AC 543 ms
115,296 KB
testcase_07 AC 198 ms
85,376 KB
testcase_08 AC 259 ms
89,540 KB
testcase_09 AC 161 ms
82,364 KB
testcase_10 AC 323 ms
96,012 KB
testcase_11 AC 868 ms
146,060 KB
testcase_12 AC 542 ms
115,756 KB
testcase_13 AC 316 ms
96,712 KB
testcase_14 AC 150 ms
81,548 KB
testcase_15 AC 434 ms
105,372 KB
testcase_16 AC 1,004 ms
156,636 KB
testcase_17 AC 1,036 ms
160,576 KB
testcase_18 AC 318 ms
95,780 KB
testcase_19 AC 889 ms
147,684 KB
testcase_20 AC 173 ms
84,424 KB
testcase_21 AC 236 ms
89,324 KB
testcase_22 AC 732 ms
132,244 KB
testcase_23 AC 471 ms
109,436 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