結果

問題 No.912 赤黒木
ユーザー lam6er
提出日時 2025-04-15 23:06:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 413 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 81,904 KB
実行使用メモリ 78,056 KB
最終ジャッジ日時 2025-04-15 23:08:39
合計ジャッジ時間 8,068 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
# Read red edges (not used)
for _ in range(n-1):
    input()

degree = [0] * (n + 1)  # 1-based indexing

# Read black edges and compute degrees
for _ in range(n-1):
    c, d = map(int, input().split())
    degree[c] += 1
    degree[d] += 1

count = 0
for i in range(1, n+1):
    if degree[i] % 2 == 1:
        count += 1

k = count // 2
if count == 0:
    k = 1

ans = (n-1) + (k - 1)
print(ans)
0