結果

問題 No.806 木を道に
ユーザー tomarint2tomarint2
提出日時 2019-03-22 22:00:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,564 KB
実行使用メモリ 81,756 KB
最終ジャッジ日時 2023-10-19 09:09:39
合計ジャッジ時間 3,972 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,344 KB
testcase_01 AC 44 ms
53,296 KB
testcase_02 AC 44 ms
55,344 KB
testcase_03 AC 45 ms
55,344 KB
testcase_04 AC 45 ms
55,344 KB
testcase_05 AC 48 ms
55,344 KB
testcase_06 AC 44 ms
55,344 KB
testcase_07 AC 45 ms
55,344 KB
testcase_08 AC 43 ms
55,344 KB
testcase_09 AC 45 ms
55,344 KB
testcase_10 AC 93 ms
77,108 KB
testcase_11 AC 88 ms
76,900 KB
testcase_12 AC 137 ms
81,632 KB
testcase_13 AC 121 ms
79,820 KB
testcase_14 AC 136 ms
81,632 KB
testcase_15 AC 137 ms
81,632 KB
testcase_16 AC 95 ms
77,836 KB
testcase_17 AC 129 ms
81,756 KB
testcase_18 AC 83 ms
76,608 KB
testcase_19 AC 90 ms
77,292 KB
testcase_20 AC 129 ms
81,756 KB
testcase_21 AC 105 ms
79,668 KB
testcase_22 AC 144 ms
81,632 KB
testcase_23 AC 142 ms
81,632 KB
testcase_24 AC 109 ms
79,748 KB
testcase_25 AC 124 ms
81,632 KB
testcase_26 AC 96 ms
77,788 KB
testcase_27 AC 132 ms
81,632 KB
testcase_28 AC 71 ms
70,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

def solve():
    ans=0
    n=int(input())
    side=[]
    degree=[0 for i in range(n)]
    for i in range(n-1):
        a,b=map(int,input().split())
        side.append((a,b))
        degree[a-1]+=1
        degree[b-1]+=1
    c = collections.Counter(degree)
    if c[1]==2:
        return 0
    ck = sorted(c.keys(),reverse=True)

    #
    #   o--o--o
    # |||     |||
    # ooo     ooo
    # |||     |||
    # ooo     ooo

    for k in ck:
        if k > 2:
            ans+=(k-2)*c[k]
            #if c[1]>=k-2:
            #    c[1]-=k-2
            #    c[2]+=k-2
    return ans
print(solve())
0