結果
| 問題 |
No.912 赤黒木
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:22:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 528 bytes |
| コンパイル時間 | 163 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 77,952 KB |
| 最終ジャッジ日時 | 2025-06-12 16:22:48 |
| 合計ジャッジ時間 | 5,347 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 27 |
ソースコード
import sys
def main():
n = int(sys.stdin.readline())
# Skip red edges
for _ in range(n-1):
sys.stdin.readline()
# Read black edges and calculate degrees
degree = [0] * (n + 1)
for _ in range(n-1):
c, d = map(int, sys.stdin.readline().split())
degree[c] += 1
degree[d] += 1
# Calculate the sum of (max(0, degree - 2)) for all nodes
sum_degree = sum(max(0, d - 2) for d in degree)
ans = (n - 1) + sum_degree
print(ans)
if __name__ == "__main__":
main()
gew1fw