結果

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

ソースコード

diff #

n = int(input())
degree = [0] * (n + 1)

# Read red edges
for _ in range(n-1):
    a, b = map(int, input().split())
    degree[a] += 1
    degree[b] += 1

# Read black edges (not used in calculation)
for _ in range(n-1):
    c, d = map(int, input().split())

# Count leaves in red tree
m = sum(1 for i in range(1, n+1) if degree[i] == 1)
print(n + m - 3)
0