#SRD0000146. Bò Bessie bị bao vây (Cow at Large)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bò Bessie bị bao vây (Cow at Large)
Cow at Large
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
A farm has barns connected by bidirectional tunnels, forming a tree. Every barn with exactly one tunnel is an exit.
Bessie appears at a chosen barn and tries to reach an exit. Farmers immediately learn her location and may start simultaneously from exits of their choice. Both Bessie and the farmers move at the same speed, traversing one edge per time step, and each knows the other's position.
Bessie is caught if a farmer and she occupy the same barn at the same time or traverse the same tunnel in opposite directions. Otherwise she escapes if she reaches an exit without being caught.
For each starting barn , determine the minimum number of farmers who can guarantee capture, with optimal play.
Input
- The first line contains .
- Each of the next lines contains describing a bidirectional tunnel. Barns use one-based indices.
Output
Print lines. Line is the minimum number of farmers required if Bessie starts at barn .
Subtasks
- Subtask 1 (20 points): ; undirected edges; vertices in ; the graph is connected and acyclic.
- Subtask 2 (30 points): ; undirected edges; vertices in ; the graph is connected and acyclic.
- Subtask 3 (50 points): ; undirected edges; vertices in ; the graph is connected and acyclic.
Examples
Example 1
Input
7
1 2
1 3
3 4
3 5
4 6
5 7
Output
3
1
3
3
3
1
1
Explanation
Barns are exits; a farmer at the same exit catches Bessie immediately, so the corresponding outputs are . Starting at barn , the three escape branches toward leaves require three intercepting farmers, one at each exit. The same minimum holds for starts at barns .