結果

問題 No.1103 Directed Length Sum
コンテスト
ユーザー marroncastle
提出日時 2020-07-25 19:16:07
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 477 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 346 ms
コンパイル使用メモリ 84,736 KB
実行使用メモリ 1,342,464 KB
最終ジャッジ日時 2026-03-15 10:28:51
合計ジャッジ時間 3,963 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other MLE * 2 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

def dfs(v,depth,mod):
    ans[0] += depth*(depth+1)//2
    ans[0] %= mod
    for u in edge[v]:
        dfs(u,depth+1,mod)
    return

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