In recent years the Compulsive Disorder Research Institute became increasingly busy with discovering and classifying all sorts of peculiar behaviors. You have been dispatched to investigate one such strange compulsion reported amongst the innocent everyday metro travelers.
The underground metro consists of stations connected by bidirectional paths and metros with linear routes, each having a unique number. The issue concerns the displays located within the stations that show the numbers of the metros passing through their respective station in sorted order. One of your subjects proclaimed that whenever he saw a list of integers he couldn't resist calculating the sum of those even-indexed . One such list can be seen on each of the displays located inside the metro stations.
Before any assumptions can be made about those afflicted, the sum for each of the displays needs to be calculated. Unfortunately if you manually count those numbers there is a definite chance you might actually end up suffering from this specific disorder. As such you are to write a program that computes them for you, thus protecting your mind from potential insanity.
Task
Given the number of stations, , the way in which they are connected, as well as the metros, compute the necessary sum for each of the stations.
Input data
The file metro.in
contains two integers on the first line, and . The following lines each contain two integers , meaning there is a direct link between stations and .
The next lines describe the metros using three integers , and meaning that the route of the metro numbered goes from station to station .
Output data
The file metro.out
must contain lines. Line must contain a single number, the sum for the display in the station with number . If there are no trains at all passing through station , write the number on line .
Constraints and clarifications
- for all
- It is guaranteed that all stations are reachable from each other.
# | Points | Constraints |
---|---|---|
1 | 10 | , |
2 | 10 | , |
3 | 15 | , |
4 | 15 | , |
5 | 20 | , |
6 | 30 | No additional constraints |
Example
metro.in
6 4
1 2
2 4
2 6
1 3
5 2
5 6 3
4 5 1
4 3 2
1 2 4
metro.out
2
4
2
1
1
3
Explanation
The displays are showing the following numbers:
Station :
Station :
Station :
Station :
Station :
Station :