結果

問題 No.2427 Tree Distance Two
ユーザー noriocnorioc
提出日時 2023-08-18 23:07:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 344 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 164,764 KB
最終ジャッジ日時 2024-05-06 05:39:28
合計ジャッジ時間 12,255 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,248 KB
testcase_01 AC 46 ms
53,120 KB
testcase_02 AC 39 ms
53,632 KB
testcase_03 AC 617 ms
152,912 KB
testcase_04 AC 41 ms
53,248 KB
testcase_05 AC 642 ms
152,848 KB
testcase_06 AC 39 ms
53,120 KB
testcase_07 AC 434 ms
161,392 KB
testcase_08 AC 457 ms
163,628 KB
testcase_09 AC 446 ms
160,144 KB
testcase_10 AC 451 ms
164,764 KB
testcase_11 AC 464 ms
162,280 KB
testcase_12 AC 515 ms
161,044 KB
testcase_13 AC 556 ms
160,068 KB
testcase_14 AC 356 ms
147,608 KB
testcase_15 AC 41 ms
53,504 KB
testcase_16 AC 42 ms
54,016 KB
testcase_17 AC 39 ms
53,504 KB
testcase_18 AC 41 ms
54,144 KB
testcase_19 AC 41 ms
53,632 KB
testcase_20 AC 102 ms
77,312 KB
testcase_21 AC 105 ms
77,952 KB
testcase_22 AC 96 ms
77,312 KB
testcase_23 AC 89 ms
76,928 KB
testcase_24 AC 102 ms
77,568 KB
testcase_25 AC 193 ms
93,216 KB
testcase_26 AC 385 ms
120,460 KB
testcase_27 AC 291 ms
106,284 KB
testcase_28 AC 576 ms
144,472 KB
testcase_29 AC 514 ms
134,420 KB
testcase_30 AC 380 ms
116,084 KB
testcase_31 AC 261 ms
101,896 KB
testcase_32 AC 388 ms
115,908 KB
testcase_33 AC 329 ms
110,784 KB
testcase_34 AC 154 ms
88,140 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