結果

問題 No.2427 Tree Distance Two
ユーザー noriocnorioc
提出日時 2023-08-18 23:07:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 593 ms / 2,000 ms
コード長 344 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 165,216 KB
最終ジャッジ日時 2023-08-18 23:07:37
合計ジャッジ時間 14,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,436 KB
testcase_01 AC 77 ms
71,356 KB
testcase_02 AC 77 ms
71,664 KB
testcase_03 AC 593 ms
152,472 KB
testcase_04 AC 79 ms
71,676 KB
testcase_05 AC 553 ms
152,028 KB
testcase_06 AC 74 ms
71,492 KB
testcase_07 AC 450 ms
165,216 KB
testcase_08 AC 463 ms
162,384 KB
testcase_09 AC 529 ms
163,948 KB
testcase_10 AC 514 ms
162,648 KB
testcase_11 AC 519 ms
165,016 KB
testcase_12 AC 511 ms
161,720 KB
testcase_13 AC 500 ms
160,140 KB
testcase_14 AC 364 ms
150,160 KB
testcase_15 AC 78 ms
71,592 KB
testcase_16 AC 96 ms
71,596 KB
testcase_17 AC 76 ms
71,508 KB
testcase_18 AC 77 ms
71,532 KB
testcase_19 AC 77 ms
71,328 KB
testcase_20 AC 124 ms
79,036 KB
testcase_21 AC 126 ms
79,396 KB
testcase_22 AC 118 ms
78,352 KB
testcase_23 AC 112 ms
78,052 KB
testcase_24 AC 145 ms
78,964 KB
testcase_25 AC 201 ms
93,728 KB
testcase_26 AC 365 ms
123,160 KB
testcase_27 AC 288 ms
106,920 KB
testcase_28 AC 536 ms
146,708 KB
testcase_29 AC 490 ms
137,128 KB
testcase_30 AC 350 ms
118,836 KB
testcase_31 AC 322 ms
103,744 KB
testcase_32 AC 365 ms
118,556 KB
testcase_33 AC 320 ms
112,824 KB
testcase_34 AC 172 ms
88,356 KB
権限があれば一括ダウンロードができます

ソースコード

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)

ans = [0] * N
for i in range(N):
    cnt = len(adj[i])
    if cnt < 2: continue
    for v in adj[i]:
        ans[v] += cnt - 1

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