#P2047. [NOI2007] 社交网络

    ID: 989 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论2007NOI 系列最短路概率论,统计

[NOI2007] 社交网络

Description

In the study of social networks (Social Network), we often use graph theory to explain social phenomena. Consider the following problem:
There are nn people in a social circle, and the relationships between people have different strengths. We model this relationship network as an undirected graph with nn nodes. If two different people know each other, we connect an undirected edge between their corresponding nodes and assign it a positive weight cc. The smaller cc is, the closer their relationship is. We measure the closeness between two people ss and tt by the length of the shortest path between their corresponding nodes. Note that other nodes on a shortest path provide some convenience for the connection between ss and tt, that is, these nodes have a certain degree of importance for the connection between ss and tt. We can measure a node’s importance in the social network by counting the number of shortest paths that pass through a node vv. Considering that there may be multiple shortest paths between two nodes AA and BB, we modify the definition of importance as follows: let Cs,tC_{s,t} denote the number of different shortest paths from ss to tt, and let Cs,t(v)C_{s,t}(v) denote the number of shortest paths from ss to tt that pass through vv. Then define:

$$I(v)=\sum_{s \ne v,t\ne v} \frac{C_{s,t}(v)}{C_{s,t}}$$

as the importance of node vv in the social network. To make I(v)I(v) and Cs,t(v)C_{s,t}(v) meaningful, we stipulate that the social networks to be processed are connected undirected graphs, i.e., there is a shortest path of finite length between any two nodes. Given such a weighted undirected graph describing a social network, please compute the importance of each node.

Constraints:

  • For 50%50\% of the testdata, n10,m45n \le 10, m \le 45.
  • For 100%100\% of the testdata, n100,m4500n \le 100, m \le 4500, each edge weight cc is a positive integer and 1c10001 \leqslant c \leqslant 1000.
  • The graph is guaranteed to be connected, and the number of shortest paths between any two nodes does not exceed 101010^{10}.

Input Format

The first line contains two integers nn and mm, the number of nodes and undirected edges in the social network.
In the undirected graph, all nodes are numbered from 11 to nn.

Each of the next mm lines contains three integers a,b,ca, b, c describing an undirected edge connecting nodes aa and bb with weight cc.
Note that there is at most one undirected edge between any two nodes, and there are no self-loops in the undirected graph (that is, there is no undirected edge whose two endpoints are the same node).

Output Format

Output nn lines, each containing a real number rounded to 33 decimal places. The real number on the ii-th line represents the importance of node ii in the social network.

4 4
1 2 1
2 3 1
3 4 1
4 1 1
1.000
1.000
1.000
1.000

Hint

For node 11, only the shortest paths from node 22 to node 44 and from node 44 to node 22 pass through node 11. Moreover, there are 22 shortest paths between node 22 and node 44. Therefore, by the definition, the importance of node 11 is 12+12=1\frac{1}{2}+\frac{1}{2}=1. Due to the symmetry of the graph, the importance of the other three nodes is also 11.

Translated by ChatGPT 5