結果

問題 No.912 赤黒木
ユーザー gew1fw
提出日時 2025-06-12 20:58:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 616 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 144,384 KB
最終ジャッジ日時 2025-06-12 21:01:50
合計ジャッジ時間 5,649 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 3 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1

    # Read red edges, but ignore them
    for _ in range(N-1):
        ptr += 2

    # Read black edges
    degrees = [0] * (N + 1)
    for _ in range(N-1):
        a = int(input[ptr])
        b = int(input[ptr+1])
        ptr += 2
        degrees[a] += 1
        degrees[b] += 1

    # Count the number of leaves in the black tree
    L = sum(1 for i in range(1, N+1) if degrees[i] == 1)

    # Compute the result
    result = (N - 1) + (L - 2)
    print(result)

if __name__ == "__main__":
    main()
0