結果

問題 No.1103 Directed Length Sum
ユーザー marroncastlemarroncastle
提出日時 2020-07-25 14:35:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 562 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 352,156 KB
最終ジャッジ日時 2023-09-09 12:37:14
合計ジャッジ時間 32,374 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,784 KB
testcase_01 AC 16 ms
7,808 KB
testcase_02 TLE -
testcase_03 AC 2,188 ms
133,568 KB
testcase_04 AC 1,883 ms
83,984 KB
testcase_05 TLE -
testcase_06 AC 1,162 ms
57,728 KB
testcase_07 AC 230 ms
20,272 KB
testcase_08 AC 376 ms
26,240 KB
testcase_09 AC 146 ms
15,804 KB
testcase_10 AC 535 ms
33,048 KB
testcase_11 AC 2,092 ms
91,140 KB
testcase_12 AC 1,171 ms
58,204 KB
testcase_13 AC 558 ms
33,796 KB
testcase_14 AC 114 ms
13,852 KB
testcase_15 AC 952 ms
47,128 KB
testcase_16 AC 2,351 ms
101,232 KB
testcase_17 AC 2,455 ms
105,468 KB
testcase_18 AC 535 ms
33,036 KB
testcase_19 AC 2,156 ms
93,296 KB
testcase_20 AC 174 ms
17,392 KB
testcase_21 AC 324 ms
24,668 KB
testcase_22 AC 1,692 ms
77,388 KB
testcase_23 AC 949 ms
49,860 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 = sum(nums)%mod
print(ans)
0