You are given an undirected connected graph with no cycles. You must paint every node either blue or red. Painting in blue costs 1 per node, while painting in red costs 2 per node. Your goal is to minimize the total cost of painting the tree. There is just one restriction: Each node can have, at most, one adjacent node with the same color than itself.
Input consists of several trees, each one with the number of nodes , followed by pairs for the edges. Nodes are numbered from 0. Assume .
Print the minimum cost to color each tree.
Author: Salvador Roura
Generation: 2026-01-25T10:23:38.653Z
© Jutge.org, 2006–2026.
https://jutge.org