Transmitters
InterviewTime limit2sMemory limit1024 MB
Given a tree of chambers, find the fewest Wi-Fi transmitters so every tunnel is covered by a transmitter at an endpoint or two transmitters next to it.
- Level
Medium6 of 10
- Topics
- Tree, Dynamic programming, DFS
- Solved
- No attempts yet
Statement
Bajtazar has become the new director of a historic salt mine. To attract more tourists, he wants to install wireless internet in the mine's tunnels.
The mine has chambers connected by tunnels. You can walk from any chamber to any other chamber through the tunnels. Bajtazar wants to place Wi-Fi transmitters in the chambers so that internet is available in every tunnel. To use the internet in the tunnel connecting chambers and , at least one of the following must hold:
- There is a transmitter in chamber or in chamber .
- The set of chambers reachable from or using at most one tunnel contains at least two transmitters.
Find the minimum number of transmitters Bajtazar must place. Any number of transmitters can be placed in a single chamber.
Input
The first line contains a positive integer , the number of chambers. Chambers are numbered from 1 to .
Each of the next lines contains two integers and (, ) separated by a single space, meaning chambers and are connected by a tunnel.
Output
The first and only line of the standard output should contain one integer, the minimum number of transmitters Bajtazar must place.