結果

問題 No.1103 Directed Length Sum
ユーザー marroncastlemarroncastle
提出日時 2020-07-25 17:22:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 670 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 361,692 KB
最終ジャッジ日時 2023-09-09 17:40:02
合計ジャッジ時間 14,344 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,928 KB
testcase_01 AC 17 ms
7,744 KB
testcase_02 TLE -
testcase_03 AC 2,132 ms
141,324 KB
testcase_04 AC 2,119 ms
88,572 KB
testcase_05 TLE -
testcase_06 AC 1,316 ms
60,456 KB
testcase_07 AC 280 ms
20,744 KB
testcase_08 AC 437 ms
27,400 KB
testcase_09 AC 157 ms
16,156 KB
testcase_10 AC 620 ms
34,476 KB
testcase_11 AC 2,356 ms
95,972 KB
testcase_12 AC 1,374 ms
61,080 KB
testcase_13 AC 640 ms
35,336 KB
testcase_14 AC 129 ms
14,260 KB
testcase_15 AC 1,014 ms
49,468 KB
testcase_16 AC 2,652 ms
106,544 KB
testcase_17 AC 2,779 ms
110,936 KB
testcase_18 AC 634 ms
34,500 KB
testcase_19 AC 2,455 ms
98,112 KB
testcase_20 AC 216 ms
17,960 KB
testcase_21 AC 409 ms
25,572 KB
testcase_22 AC 1,966 ms
81,564 KB
testcase_23 AC 1,125 ms
52,416 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)]
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
for i in range(N):
    if roots[i]==True:
        dfs(i,mod)
        break
ans = sum(nums)
ans %= mod
print(ans)
0