結果

問題 No.1103 Directed Length Sum
コンテスト
ユーザー marroncastle
提出日時 2020-07-03 22:37:03
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 546 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 357 ms
コンパイル使用メモリ 20,568 KB
実行使用メモリ 375,212 KB
最終ジャッジ日時 2026-04-06 02:40:47
合計ジャッジ時間 31,313 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 WA * 1 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(10**8)

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

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