Traffic Volume Survey
Time limit2sMemory limit1024 MB
Given a connected graph with N cities and N roads and M vehicle groups, count for each road how many vehicles could use it on some simple path.
- Level
Medium6 of 10
- Topics
- Graph, Tree, Prefix sum
- Solved
- No attempts yet
Problem
The Sublime Nation has cities numbered from to . Modeled after Line 2 of the Seoul Metropolitan Subway, which passes Hanyang University, there are also roads numbered from to . Each road connects two different cities, and no two roads connect the same pair of cities. In other words, the road network of the Sublime Nation is a simple graph. Every city can reach every other city by road.
Input
Jeonghwi joined Hyundai Mobis and was assigned to analyze traffic volume on each road to help develop efficient self-driving software. Given the departure and destination cities of vehicle groups, you must find the number of vehicles that pass through each road.
The -th vehicle group has vehicles. It travels from its departure city to its destination city, using each city and each road at most once. There may be several such routes. Since the worst case must be considered, each road that the group might use counts all vehicles as passing through it. In other words, you must count the vehicles that could pass through each road.
Jeonghwi solved this in time, but he wants a faster method. Help him solve the problem efficiently.
Output
Print lines. On the -th line, print the number of vehicles that could pass through the -th road.