This page is still under construction.

Parts of this page are still being built. What you see may change.

Traffic Volume Survey

Time limit2sMemory limit1024 MB

Summary
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 NN cities numbered from 11 to NN. Modeled after Line 2 of the Seoul Metropolitan Subway, which passes Hanyang University, there are also NN roads numbered from 11 to NN. 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 MM vehicle groups, you must find the number of vehicles that pass through each road.

The ii-th vehicle group has wiw_i 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 wiw_i vehicles as passing through it. In other words, you must count the vehicles that could pass through each road.

Jeonghwi solved this in O(NM)O(NM) time, but he wants a faster method. Help him solve the problem efficiently.

Output

Print NN lines. On the ii-th line, print the number of vehicles that could pass through the ii-th road.

Examples1

  1. Example 1

    Input
    7 2
    1 2
    1 3
    2 4
    2 5
    3 6
    3 7
    2 3
    6 7 2
    5 6 3
    
    Expected output
    3
    3
    0
    3
    5
    2
    3