Dragonfly
Time limit5sMemory limit1024 MB
Each dragonfly flies along the unique tree path from pond 1 to its home pond, eating one bug per pond; count the distinct species it eats.
Statement
Dragonflies can be seen around ponds at Botanic Gardens and Bishan Park. In one of the denser forested areas, Benson the Rabbit has noted down ponds that the dragonflies fly around. Pond () has bugs that the dragonflies can eat. The bugs at pond belong to species .
Benson has also noted down trails. Trail () connects two distinct ponds and in both directions. Dragonflies can travel from any pond to any other pond using only the trails.
Benson has captured dragonflies and intends to release them one at a time at pond . Dragonfly () has a home pond and travels to pond without visiting any pond more than once, using only the trails. The dragonflies are released in increasing order, from dragonfly to dragonfly . After a dragonfly is released, it eats one bug at every pond it visits, including pond . The count at each of those ponds drops by if it is not .
Help Benson determine the number of distinct species of bugs eaten by each dragonfly during its journey.
Input
The first line contains two space-separated integers and . The next line contains space-separated integers . The next line contains space-separated integers . The next line contains space-separated integers . Each of the next lines contains two space-separated integers, where the th of these lines contains and .
Output
Output a single line with space-separated integers. The th integer is the number of distinct species of bugs eaten by dragonfly .
Constraints
- (for all )
- (for each )
- , (for each )
- (for each )