結果

問題 No.1103 Directed Length Sum
ユーザー ttrttr
提出日時 2020-07-03 22:37:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,152 ms / 3,000 ms
コード長 465 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,536 KB
実行使用メモリ 190,788 KB
最終ジャッジ日時 2023-10-17 05:38:43
合計ジャッジ時間 11,789 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,280 KB
testcase_01 AC 43 ms
53,280 KB
testcase_02 AC 442 ms
190,788 KB
testcase_03 AC 341 ms
186,248 KB
testcase_04 AC 662 ms
124,016 KB
testcase_05 AC 1,152 ms
156,528 KB
testcase_06 AC 462 ms
107,184 KB
testcase_07 AC 130 ms
81,908 KB
testcase_08 AC 181 ms
87,044 KB
testcase_09 AC 108 ms
80,188 KB
testcase_10 AC 246 ms
91,644 KB
testcase_11 AC 733 ms
128,528 KB
testcase_12 AC 458 ms
107,488 KB
testcase_13 AC 248 ms
92,116 KB
testcase_14 AC 95 ms
79,356 KB
testcase_15 AC 368 ms
100,520 KB
testcase_16 AC 825 ms
134,436 KB
testcase_17 AC 869 ms
136,696 KB
testcase_18 AC 237 ms
91,548 KB
testcase_19 AC 768 ms
129,668 KB
testcase_20 AC 115 ms
80,840 KB
testcase_21 AC 173 ms
86,408 KB
testcase_22 AC 606 ms
119,828 KB
testcase_23 AC 366 ms
101,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

root = par.index(-1)

ans = 0
mod = 10**9+7
q = deque()
q.append(root)
while q:
    temp = q.pop()
    p = temp%N
    rnk = temp//N
    ans += rnk*(rnk+1)//2
    ans %= mod
    for v in E[p]:
        q.append((rnk+1)*N+v)

print(ans)
0