結果

問題 No.1103 Directed Length Sum
ユーザー kohei2019kohei2019
提出日時 2022-07-21 23:51:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 486 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 85,732 KB
実行使用メモリ 216,896 KB
最終ジャッジ日時 2023-09-16 07:15:56
合計ジャッジ時間 19,574 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,564 KB
testcase_01 AC 89 ms
71,708 KB
testcase_02 WA -
testcase_03 AC 695 ms
216,896 KB
testcase_04 AC 1,000 ms
136,672 KB
testcase_05 AC 1,807 ms
176,176 KB
testcase_06 AC 681 ms
112,672 KB
testcase_07 AC 233 ms
86,224 KB
testcase_08 AC 307 ms
91,336 KB
testcase_09 AC 184 ms
83,324 KB
testcase_10 AC 382 ms
95,468 KB
testcase_11 AC 1,113 ms
137,852 KB
testcase_12 AC 671 ms
113,012 KB
testcase_13 AC 387 ms
95,572 KB
testcase_14 AC 174 ms
82,324 KB
testcase_15 AC 542 ms
105,820 KB
testcase_16 AC 1,283 ms
148,904 KB
testcase_17 AC 1,348 ms
151,880 KB
testcase_18 AC 381 ms
95,308 KB
testcase_19 AC 1,159 ms
143,116 KB
testcase_20 AC 199 ms
84,384 KB
testcase_21 AC 284 ms
89,592 KB
testcase_22 AC 929 ms
127,504 KB
testcase_23 AC 579 ms
107,264 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)
0