結果

問題 No.2427 Tree Distance Two
ユーザー lloyzlloyz
提出日時 2023-08-18 22:01:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 831 ms / 2,000 ms
コード長 338 bytes
コンパイル時間 1,218 ms
コンパイル使用メモリ 86,740 KB
実行使用メモリ 165,408 KB
最終ジャッジ日時 2023-08-18 22:01:43
合計ジャッジ時間 16,897 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,544 KB
testcase_01 AC 95 ms
71,524 KB
testcase_02 AC 96 ms
71,540 KB
testcase_03 AC 796 ms
151,988 KB
testcase_04 AC 95 ms
71,712 KB
testcase_05 AC 831 ms
152,104 KB
testcase_06 AC 96 ms
71,628 KB
testcase_07 AC 570 ms
165,408 KB
testcase_08 AC 674 ms
163,188 KB
testcase_09 AC 609 ms
164,316 KB
testcase_10 AC 628 ms
163,148 KB
testcase_11 AC 629 ms
164,480 KB
testcase_12 AC 681 ms
161,468 KB
testcase_13 AC 713 ms
160,312 KB
testcase_14 AC 419 ms
145,656 KB
testcase_15 AC 96 ms
71,672 KB
testcase_16 AC 96 ms
71,608 KB
testcase_17 AC 96 ms
71,600 KB
testcase_18 AC 97 ms
71,584 KB
testcase_19 AC 95 ms
71,800 KB
testcase_20 AC 149 ms
79,244 KB
testcase_21 AC 150 ms
79,464 KB
testcase_22 AC 138 ms
77,968 KB
testcase_23 AC 134 ms
78,024 KB
testcase_24 AC 149 ms
79,272 KB
testcase_25 AC 290 ms
94,404 KB
testcase_26 AC 526 ms
123,496 KB
testcase_27 AC 395 ms
106,792 KB
testcase_28 AC 739 ms
146,784 KB
testcase_29 AC 658 ms
137,224 KB
testcase_30 AC 497 ms
119,224 KB
testcase_31 AC 365 ms
103,604 KB
testcase_32 AC 522 ms
118,792 KB
testcase_33 AC 467 ms
113,084 KB
testcase_34 AC 218 ms
88,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n = int(input())
G = defaultdict(list)
for _ in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)

ANS = [0 for _ in range(n)]
for i in range(n):
    L = G[i]
    num = len(L)
    for j in L:
        ANS[j] += num - 1
print(*ANS, sep='\n')
0