結果

問題 No.912 赤黒木
ユーザー gew1fw
提出日時 2025-06-12 21:05:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 354 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 78,464 KB
最終ジャッジ日時 2025-06-12 21:06:21
合計ジャッジ時間 8,536 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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