結果

問題 No.1103 Directed Length Sum
ユーザー marroncastlemarroncastle
提出日時 2020-07-25 14:41:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 599 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 353,736 KB
最終ジャッジ日時 2023-09-09 12:46:43
合計ジャッジ時間 14,983 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,764 KB
testcase_01 AC 16 ms
7,848 KB
testcase_02 TLE -
testcase_03 AC 2,346 ms
133,596 KB
testcase_04 AC 2,126 ms
84,196 KB
testcase_05 TLE -
testcase_06 AC 1,319 ms
57,748 KB
testcase_07 AC 299 ms
20,332 KB
testcase_08 AC 456 ms
26,388 KB
testcase_09 AC 179 ms
15,708 KB
testcase_10 AC 639 ms
33,064 KB
testcase_11 AC 2,436 ms
90,996 KB
testcase_12 AC 1,389 ms
58,268 KB
testcase_13 AC 681 ms
33,816 KB
testcase_14 AC 131 ms
13,848 KB
testcase_15 AC 1,047 ms
47,268 KB
testcase_16 AC 2,706 ms
101,292 KB
testcase_17 AC 2,791 ms
105,300 KB
testcase_18 AC 668 ms
33,104 KB
testcase_19 AC 2,472 ms
93,340 KB
testcase_20 AC 215 ms
17,456 KB
testcase_21 AC 412 ms
24,744 KB
testcase_22 AC 1,955 ms
77,568 KB
testcase_23 AC 1,131 ms
50,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**8)
input=sys.stdin.readline

def dfs(v,mod):
  nums[v] = 0
  child[v] = 0
  if len(edge[v])==0:
    return
  for u in edge[v]:
    if nums[u] == -1:
      dfs(u,mod)
    nums[v] += nums[u]+child[u]+1
    child[v] += child[u]+1
  nums[v] %= mod
  child[v] %= mod
  return

N = int(input())
mod = 10**9+7
edge = [[] for _ in range(N)]
for _ in range(N-1):
  a,b = map(int, input().split())
  edge[a-1].append(b-1)
nums = [-1]*N
child = [-1]*N
for i in range(N):
  if nums[i] == -1:
    dfs(i,mod)
ans = 0
for i in range(N):
  ans += nums[i]
  ans %= mod
print(ans)
0