結果

問題 No.1103 Directed Length Sum
ユーザー tikitaka1201tikitaka1201
提出日時 2020-07-09 21:43:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,835 ms / 3,000 ms
コード長 393 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 263,752 KB
最終ジャッジ日時 2024-04-17 01:47:23
合計ジャッジ時間 17,255 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
51,968 KB
testcase_01 AC 41 ms
51,840 KB
testcase_02 AC 791 ms
192,768 KB
testcase_03 AC 755 ms
263,752 KB
testcase_04 AC 1,060 ms
124,672 KB
testcase_05 AC 1,835 ms
157,952 KB
testcase_06 AC 691 ms
108,544 KB
testcase_07 AC 202 ms
83,712 KB
testcase_08 AC 279 ms
87,936 KB
testcase_09 AC 155 ms
80,896 KB
testcase_10 AC 367 ms
92,160 KB
testcase_11 AC 1,126 ms
129,024 KB
testcase_12 AC 673 ms
108,416 KB
testcase_13 AC 365 ms
92,800 KB
testcase_14 AC 139 ms
79,872 KB
testcase_15 AC 550 ms
101,504 KB
testcase_16 AC 1,261 ms
135,808 KB
testcase_17 AC 1,326 ms
137,984 KB
testcase_18 AC 355 ms
92,032 KB
testcase_19 AC 1,198 ms
130,560 KB
testcase_20 AC 177 ms
82,432 KB
testcase_21 AC 258 ms
86,912 KB
testcase_22 AC 960 ms
120,960 KB
testcase_23 AC 579 ms
103,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
mod=10**9+7
es=[[] for _ in range(n)]
par=[0]*n
for _ in range(n-1):
    a,b=map(int,input().split())
    es[a-1].append(b-1)
    par[b-1]=1

for i in range(n):
    if par[i]==0:
        root=i
        break
stack=[(root,0)]
ans=0
while stack:
    now,depth=stack.pop()
    ans+=depth*(depth+1)//2
    ans%=mod
    for e in es[now]:
        stack.append((e, depth+1))
print(ans)
0