結果

問題 No.2427 Tree Distance Two
ユーザー FromBooskaFromBooska
提出日時 2023-08-18 21:51:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 634 ms / 2,000 ms
コード長 410 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 127,652 KB
最終ジャッジ日時 2024-05-06 03:50:14
合計ジャッジ時間 12,531 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,096 KB
testcase_01 AC 34 ms
52,096 KB
testcase_02 AC 33 ms
52,096 KB
testcase_03 AC 612 ms
114,944 KB
testcase_04 AC 35 ms
51,712 KB
testcase_05 AC 634 ms
114,720 KB
testcase_06 AC 37 ms
52,480 KB
testcase_07 AC 522 ms
127,180 KB
testcase_08 AC 568 ms
126,592 KB
testcase_09 AC 519 ms
126,272 KB
testcase_10 AC 545 ms
127,652 KB
testcase_11 AC 553 ms
125,520 KB
testcase_12 AC 562 ms
123,208 KB
testcase_13 AC 589 ms
120,212 KB
testcase_14 AC 297 ms
113,576 KB
testcase_15 AC 34 ms
52,480 KB
testcase_16 AC 35 ms
52,992 KB
testcase_17 AC 36 ms
52,352 KB
testcase_18 AC 35 ms
52,736 KB
testcase_19 AC 38 ms
52,352 KB
testcase_20 AC 89 ms
77,312 KB
testcase_21 AC 93 ms
77,480 KB
testcase_22 AC 77 ms
76,920 KB
testcase_23 AC 78 ms
76,392 KB
testcase_24 AC 87 ms
77,288 KB
testcase_25 AC 183 ms
86,244 KB
testcase_26 AC 384 ms
99,664 KB
testcase_27 AC 285 ms
93,104 KB
testcase_28 AC 568 ms
110,956 KB
testcase_29 AC 515 ms
107,040 KB
testcase_30 AC 378 ms
98,816 KB
testcase_31 AC 261 ms
91,408 KB
testcase_32 AC 364 ms
98,768 KB
testcase_33 AC 335 ms
96,328 KB
testcase_34 AC 145 ms
82,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 木、閉路なし、ということはdegreeだけで計算できるか

N = int(input())
edges = [[] for i in range(N+1)]
degree = [0]*(N+1)
for i in range(N-1):
    u, v = map(int, input().split())
    edges[u].append(v)
    edges[v].append(u)
    degree[u] += 1
    degree[v] += 1
    
for i in range(1, N+1):
    count = 0
    for nxt in edges[i]:
        count += max(0, degree[nxt]-1)
    print(count)
0