結果

問題 No.806 木を道に
ユーザー stngstng
提出日時 2022-07-02 17:46:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 90,828 KB
最終ジャッジ日時 2023-08-18 09:06:06
合計ジャッジ時間 8,428 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,460 KB
testcase_01 AC 94 ms
71,420 KB
testcase_02 AC 91 ms
71,528 KB
testcase_03 AC 92 ms
71,584 KB
testcase_04 AC 92 ms
71,348 KB
testcase_05 AC 91 ms
71,456 KB
testcase_06 AC 94 ms
71,460 KB
testcase_07 AC 89 ms
71,320 KB
testcase_08 AC 90 ms
71,696 KB
testcase_09 AC 89 ms
71,652 KB
testcase_10 AC 140 ms
80,380 KB
testcase_11 AC 138 ms
79,984 KB
testcase_12 AC 213 ms
87,640 KB
testcase_13 AC 178 ms
84,620 KB
testcase_14 AC 204 ms
87,376 KB
testcase_15 AC 209 ms
88,000 KB
testcase_16 AC 146 ms
80,980 KB
testcase_17 AC 194 ms
85,600 KB
testcase_18 AC 132 ms
77,720 KB
testcase_19 AC 142 ms
80,532 KB
testcase_20 AC 195 ms
85,348 KB
testcase_21 AC 158 ms
81,640 KB
testcase_22 AC 228 ms
88,984 KB
testcase_23 AC 236 ms
88,924 KB
testcase_24 AC 152 ms
84,128 KB
testcase_25 AC 167 ms
85,060 KB
testcase_26 AC 138 ms
81,816 KB
testcase_27 AC 187 ms
90,828 KB
testcase_28 AC 126 ms
77,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n = int(input())
ab = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ab[a].append(b)
    ab[b].append(a)

d = deque()
chk = [0]*n
ans = 0

for i in range(n):
    if len(ab[i]) > 2:
        ans += len(ab[i]) - 2

print(ans)

"""
for i in range(n):
    if chk[i] == 0:
        d.appendleft(i)
        chk[i] = 1
        while len(d):
            tmp = d.popleft()
            if chk[tmp] == 0:
                if len(ab[tmp]) > 2:
                    ans += len(ab[tmp]) - 2
                    d.
"""
0