CT035

Even Forest Split

HardAcceptance: 0.0%

A Codetikki sacred tree has an even number of nodes. Each parent-child connection is an "edge". You want to remove some edges so that the remaining disconnected subtrees each have an even number of nodes. Given a tree with an even number of nodes, return the maximum number of edges you can remove such that each remaining subtree has an even number of nodes. Input: first line n (even), then n-1 lines each with parent child.

Example 1:

Input: 10 1 2 1 3 3 4 3 5 4 6 4 7 4 8
Output: 2

Example 2:

Input: 2 1 2
Output: 0

Constraints:

2 <= n <= 10^5 (n is even) Nodes labeled 1 to n

Tags:

graph tree dfs
Loading...
Test Cases:No test cases
No test cases available.