結果

問題 No.872 All Tree Path
ユーザー roarisroaris
提出日時 2019-08-30 22:48:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 652 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 307,352 KB
最終ジャッジ日時 2024-05-01 19:35:51
合計ジャッジ時間 8,154 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def dfs(cur, prev):
    if cur == None:
        exit()
        
    if cur < 0 or cur >= N:
        exit()
    res = 1
    
    for next_node, w in adj_list[cur]:
        if next_node == prev:
            continue
        if next_node == cur:
            exit()
        res += dfs(next_node, cur)
    
    return res
    
N = int(input())
adj_list = [[] for _ in range(N)]
edges = []

for _ in range(N-1):
    ui, vi, wi = map(int, input().split())
    edges.append((ui-1, vi-1, wi))
    adj_list[ui-1].append((vi-1, wi))
    adj_list[vi-1].append((ui-1, wi))

dfs(0, None)
ans = 0
0