結果

問題 No.2427 Tree Distance Two
ユーザー noriocnorioc
提出日時 2023-08-18 23:01:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 447 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 171,224 KB
最終ジャッジ日時 2023-08-18 23:01:28
合計ジャッジ時間 9,041 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
71,892 KB
testcase_01 AC 101 ms
71,596 KB
testcase_02 AC 119 ms
71,452 KB
testcase_03 AC 1,672 ms
171,200 KB
testcase_04 AC 103 ms
71,208 KB
testcase_05 AC 1,436 ms
171,224 KB
testcase_06 AC 106 ms
71,712 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

N = int(input())
adj = defaultdict(list)
for _ in range(N-1):
    u, v = map(lambda x: int(x)-1, input().split())
    adj[u].append(v)
    adj[v].append(u)


def dfs(v, prev, depth):
    if depth == 2: return 1
    res = 0
    for to in adj[v]:
        if to == prev: continue
        res += dfs(to, v, depth+1)
    return res


ans = []
for i in range(N):
    ans.append(dfs(i, -1, 0))

print(*ans, sep='\n')
0