結果

問題 No.1103 Directed Length Sum
ユーザー tyawanmusityawanmusi
提出日時 2020-07-03 22:09:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,747 ms / 3,000 ms
コード長 390 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 340,068 KB
最終ジャッジ日時 2023-10-17 03:45:09
合計ジャッジ時間 16,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,564 KB
testcase_01 AC 33 ms
53,564 KB
testcase_02 AC 869 ms
340,068 KB
testcase_03 AC 715 ms
291,784 KB
testcase_04 AC 976 ms
246,752 KB
testcase_05 AC 1,747 ms
259,676 KB
testcase_06 AC 622 ms
195,436 KB
testcase_07 AC 165 ms
102,188 KB
testcase_08 AC 241 ms
118,556 KB
testcase_09 AC 125 ms
91,876 KB
testcase_10 AC 352 ms
133,540 KB
testcase_11 AC 1,049 ms
260,668 KB
testcase_12 AC 637 ms
195,628 KB
testcase_13 AC 321 ms
133,588 KB
testcase_14 AC 110 ms
87,324 KB
testcase_15 AC 487 ms
141,236 KB
testcase_16 AC 1,232 ms
258,564 KB
testcase_17 AC 1,261 ms
261,700 KB
testcase_18 AC 303 ms
133,272 KB
testcase_19 AC 1,092 ms
239,888 KB
testcase_20 AC 138 ms
91,388 KB
testcase_21 AC 209 ms
113,416 KB
testcase_22 AC 874 ms
241,972 KB
testcase_23 AC 527 ms
176,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
edge=[[]for _ in range(n)]
to=[0]*n
p=[0]*n
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  to[b]+=1
stack=[to.index(0)]
visited=set(stack)
mod=10**9+7
for i in stack:
  for j in edge[i]:
    if j in visited:continue
    visited.add(j)
    to[j]-=1
    if to[j]==0:stack.append(j)
    p[j]+=p[i]+1
print(sum(i*(i+1)//2 for i in p)%mod)
0