結果

問題 No.806 木を道に
ユーザー FromBooskaFromBooska
提出日時 2023-02-28 14:01:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 510 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 78,672 KB
最終ジャッジ日時 2023-10-13 20:27:42
合計ジャッジ時間 5,167 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,336 KB
testcase_01 AC 73 ms
71,412 KB
testcase_02 AC 79 ms
71,444 KB
testcase_03 AC 73 ms
71,280 KB
testcase_04 AC 75 ms
71,276 KB
testcase_05 AC 75 ms
71,276 KB
testcase_06 AC 75 ms
71,172 KB
testcase_07 AC 74 ms
71,272 KB
testcase_08 AC 71 ms
71,300 KB
testcase_09 AC 73 ms
71,276 KB
testcase_10 AC 114 ms
77,604 KB
testcase_11 AC 113 ms
77,332 KB
testcase_12 AC 141 ms
78,144 KB
testcase_13 AC 129 ms
77,812 KB
testcase_14 AC 139 ms
78,028 KB
testcase_15 AC 145 ms
77,944 KB
testcase_16 AC 114 ms
77,508 KB
testcase_17 AC 136 ms
77,580 KB
testcase_18 AC 103 ms
77,408 KB
testcase_19 AC 109 ms
77,300 KB
testcase_20 AC 135 ms
78,004 KB
testcase_21 AC 120 ms
77,612 KB
testcase_22 AC 148 ms
78,036 KB
testcase_23 AC 150 ms
77,788 KB
testcase_24 AC 125 ms
77,692 KB
testcase_25 AC 134 ms
78,104 KB
testcase_26 AC 113 ms
77,428 KB
testcase_27 AC 140 ms
78,672 KB
testcase_28 AC 97 ms
76,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 次数が2を超える数の合計でいい
# 現状ではたとえば[1, 3, 4, 1, 1, 1, 1]
# 辺の数は不変、つまり次数合計は変わらない
# 道になれば次数は[1, 2, 2, 2, 2, 2, 1]となる
# つまり次数2超のところを次数1のところに付け替えていけばいい

N = int(input())
degree = [0]*(N+1)
for i in range(N-1):
    a, b = map(int, input().split())
    degree[a] += 1
    degree[b] += 1

ans = 0
for i in range(1, N+1):
    ans += max(0, degree[i]-2)
print(ans)
0