結果

問題 No.1103 Directed Length Sum
ユーザー marroncastle
提出日時 2020-07-25 14:35:09
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 562 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 852,864 KB
最終ジャッジ日時 2024-06-27 05:40:08
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other MLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

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