結果

問題 No.1103 Directed Length Sum
ユーザー tikitaka1201tikitaka1201
提出日時 2020-07-09 21:45:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,453 ms / 3,000 ms
コード長 401 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 264,024 KB
最終ジャッジ日時 2024-04-17 01:49:37
合計ジャッジ時間 14,189 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,608 KB
testcase_01 AC 31 ms
52,480 KB
testcase_02 AC 724 ms
192,876 KB
testcase_03 AC 618 ms
264,024 KB
testcase_04 AC 825 ms
124,672 KB
testcase_05 AC 1,453 ms
157,932 KB
testcase_06 AC 544 ms
108,496 KB
testcase_07 AC 155 ms
83,628 KB
testcase_08 AC 209 ms
88,096 KB
testcase_09 AC 125 ms
81,056 KB
testcase_10 AC 266 ms
91,776 KB
testcase_11 AC 917 ms
129,152 KB
testcase_12 AC 558 ms
108,800 KB
testcase_13 AC 281 ms
92,660 KB
testcase_14 AC 104 ms
80,512 KB
testcase_15 AC 418 ms
101,172 KB
testcase_16 AC 1,018 ms
135,612 KB
testcase_17 AC 1,069 ms
137,984 KB
testcase_18 AC 264 ms
91,572 KB
testcase_19 AC 914 ms
130,176 KB
testcase_20 AC 135 ms
82,688 KB
testcase_21 AC 185 ms
86,528 KB
testcase_22 AC 745 ms
120,576 KB
testcase_23 AC 428 ms
103,168 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
    x=es[now]
    for e in x:
        stack.append((e, depth+1))
print(ans)
0