Cow Telephones
Time limit1sMemory limit128 MB
Given a tree with cows at its leaves and vertex capacity K plus unit edge capacity, find the maximum number of disjoint leaf-to-leaf conversation paths.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Greedy, DFS
- Solved
- No attempts yet
Problem
The cows have built a telephone network. For this problem it can be viewed as an undirected tree with vertices (), numbered through . Each vertex is a telephone switchboard, and each edge is a telephone wire joining two switchboards. Edge is given by two integers and , the two vertices it connects (, , ).
Some switchboards have exactly one wire connecting them to another switchboard; these are the leaves of the tree, and each leaf is a telephone booth in a cow field.
For two cows to talk, their conversation travels along the unique shortest path between the two vertices where the cows stand. A single switchboard can handle at most simultaneous conversations (), and at most one conversation may pass through any given wire at any one time.
Given that there is one cow at every leaf of the tree, what is the maximum number of pairs of cows that can talk at the same time? Each cow may take part in at most one conversation.
Consider this six-vertex telephone network with :
1 5 C1 C5
| | || ||
2---4 --> |2---4|
| | || ||
3 6 C3 C6
There are cows at vertices and . If cow talks to cow and cow talks to cow , no switchboard exceeds its limit, so the answer for this example is (two pairs of cows talking simultaneously).
Input
- Line 1: Two space-separated integers and .
- Lines 2 to : Line contains two space-separated integers and for edge .
Output
- Line 1: The maximum number of pairs of cows that can hold conversations simultaneously.