#P5882. [CTSC2015] misc

[CTSC2015] misc

Description

Xiaoqiang and Mr. B are good friends.

Besides Mr. B, Xiaoqiang also has many good friends, such as Jie Mei.

Besides Xiaoqiang, Mr. B also has many good friends, such as Mr. R. They also have many mutual friends, such as Xiaohua, Cong Niang, and another 33 people.

Mr. B realized that relationships between people can be viewed as an undirected graph: each person is a vertex, and each relationship is an edge.

Different people have different influence in society. Let aia_i denote the influence of the ii-th person.

Relationships between people also vary: they may be very close, or just casual acquaintances; they may stick together every day, or contact only once a year. Therefore, we use a length edge weight bjb_j to describe the closeness of the two users connected by the jj-th edge: the smaller the length, the closer they are. At the same time, we use a width edge weight cjc_j to describe the communication frequency of the two users connected by the jj-th edge: the larger the width, the more frequently they communicate.

The length of a path is the sum of the length edge weights of all edges on the path. The width of a path is the product of the width edge weights of all edges on the path.

When two people ss and tt want to communicate, they will choose a shortest path (in terms of length). Since there may be multiple shortest paths, we define the width of the shortest paths from ss to tt as σst\sigma_{st}, which is the sum of the widths of all shortest (minimum-length) paths from ss to tt. Also, let σst(v)\sigma_{st}(v) denote the sum of the widths of all shortest paths from ss to tt that pass through vv, i.e., the influence of vv on s,ts,t.

The spreading power R(v)R(v) of a person vv in the graph is defined as:

$$R(v)=\sum\limits_{s \ne v \ne t} \frac{a_s a_t \sigma_{st}(v)}{\sigma_{st}}$$

That is, for all ordered pairs of vertices in the graph that do not include vv, compute the influence of vv on that pair divided by the total width of the shortest paths for that pair, then multiply by the influences of the two endpoints, and finally sum the results over all such pairs to obtain the spreading power of the vertex.

Mr. B wants to quickly know the spreading power of every vertex in the graph. When he asked Xiaoqiang, Xiaoqiang said: “I have a brilliant method, but the statement is too short to write it down.”

Do you know how to do it?

Input Format

The first line contains 22 positive integers nn and mm, representing the number of vertices and the number of edges in the graph.

The next nn lines: the ii-th line contains one non-negative integer aia_i, representing the influence of the ii-th person.

The next mm lines: the jj-th line contains 33 integers xjx_j, yjy_j, bjb_j and one real number cjc_j, meaning there is an edge between vertex xjx_j and vertex yjy_j with length edge weight bjb_j and width edge weight cjc_j.

Output Format

Output nn lines. The ii-th line contains one real number R(i)R(i), representing the spreading power of the ii-th vertex in the graph.

5 5
1
2
3
4
5
1 2 2 0.7
3 4 2 0.9
1 3 1 1.1
2 4 1 1.3
4 5 10 2

4.762887
8.621053
9.378947
67.237113
0.000000

Hint

Scoring

We will compare each number in the output file with the reference answer. If the relative error or absolute error of that number does not exceed 10610^{-6}, it will be judged correct. For numbers whose reference answer is 00, the absolute error must not exceed 10610^{-6} to be judged correct.

If the number of correct outputs is qq, then your score on that test point is  5(qn)7\left\lfloor\ 5(\dfrac{q}{n})^7 \right\rfloor.

Constraints

For test points 1,2,3,41,2,3,4, n100n \le 100.

For test points 5,6,7,85,6,7,8, all bj=1b_j=1.

For test points 9,10,11,129,10,11,12, m=n1m=n-1.

For test points 1,3,5,7,9,11,13,15,17,191,3,5,7,9,11,13,15,17,19, all ai=1a_i=1.

For test points 1,2,5,6,9,10,13,14,17,181,2,5,6,9,10,13,14,17,18, all cj=1c_j=1.

For all testdata, n1000n \le 1000, m4×103m \le 4 \times 10^3, 0<aj2550<a_j \le 255, 0<bj150<b_j \le 15, 0.5cj20.5 \le c_j \le 2, and the fractional part of cjc_j has at most 1212 digits. The graph is guaranteed to be connected.

Translated by ChatGPT 5