UACC 1 P4 - Converging Streams

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types

In the flourishing land of Unionville, many streams flow from the mountains to nourish the village below. At various points, a stream may diverge into two, or two streams may converge into one. This occurs at exactly N junction points numbered from 1 to N. Connecting each of these junction points are M stream segments, the ith of which directs fi% of the water in junction ui into junction vi.

Recently, some of the junctions have become polluted! Water at every junction has a measurable pollution value, which begins at 0 at the source and increases by pi upon reaching junction i. When water from two streams mix at a converging junction, the pollution values from each stream are averaged, weighted proportionally based on the volume of water in each stream, before pi is added to the pollution value.

Until the pollution is cleaned up, the village chief needs to decide the safest places to source water for agriculture. Please help him determine the average pollution value of the water at each junction.

Constraints

All water starts at a single diverging source junction, which can flow to every other junction.

It is impossible to start at a junction, travel any number of streams, and return to the same junction.

The volume of water at every junction is guaranteed to be greater than 1016.

2N105

1M1.5N

1ui,viN

1fi100

0pi100

Input Specification

The first line contains two integers, N and M.

The ith of the following M lines contain three integers, ui and vi, and fi.

The next line contains N integers, p1,p2,,pN.

Output Specification

Output N lines, the ith line of which contains a real number denoting the average pollution value at the ith junction. Your answer will be considered correct if it is within an absolute or relative error of 109.

Sample Input

Copy
6 8
2 6 100
3 4 41
3 2 59
4 2 100
5 4 27
5 3 73
6 1 62
6 1 38
8 73 40 36 100 54

Sample Output

Copy
284.6948
222.6948
140
157.029334270156
100
276.6948

Explanation for Sample Output

The river system looks like this:


Comments

There are no comments at the moment.