結果

問題 No.1103 Directed Length Sum
ユーザー kohei2019kohei2019
提出日時 2022-07-21 23:52:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,631 ms / 3,000 ms
コード長 496 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 216,852 KB
最終ジャッジ日時 2023-09-16 07:18:58
合計ジャッジ時間 17,110 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,664 KB
testcase_01 AC 96 ms
71,732 KB
testcase_02 AC 803 ms
204,148 KB
testcase_03 AC 680 ms
216,852 KB
testcase_04 AC 980 ms
136,692 KB
testcase_05 AC 1,631 ms
176,440 KB
testcase_06 AC 645 ms
112,952 KB
testcase_07 AC 234 ms
86,532 KB
testcase_08 AC 322 ms
91,120 KB
testcase_09 AC 191 ms
83,556 KB
testcase_10 AC 382 ms
95,516 KB
testcase_11 AC 1,047 ms
137,924 KB
testcase_12 AC 669 ms
113,076 KB
testcase_13 AC 387 ms
96,032 KB
testcase_14 AC 178 ms
82,332 KB
testcase_15 AC 539 ms
105,724 KB
testcase_16 AC 1,202 ms
148,944 KB
testcase_17 AC 1,224 ms
152,020 KB
testcase_18 AC 382 ms
95,432 KB
testcase_19 AC 1,088 ms
143,108 KB
testcase_20 AC 210 ms
84,256 KB
testcase_21 AC 276 ms
89,596 KB
testcase_22 AC 888 ms
127,552 KB
testcase_23 AC 574 ms
107,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N = int(input())
lsg = [[] for i in range(N)]
per = [0]*(N)
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    lsg[a].append(b)
    per[b] += 1
r = -1
for i in range(N):
    if per[i] == 0:
        r = i
        break
d = collections.deque([r])
depth = [0]*(N)
while d:
    x = d.popleft()
    for j in lsg[x]:
        depth[j] = depth[x]+1
        d.append(j)
ans = 0
for i in range(N):
    ans += (depth[i])*(depth[i]+1)//2
print(ans%(10**9+7))
0