#P2047. [NOI2007] 社交网络
[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 people in a social circle, and the relationships between people have different strengths. We model this relationship network as an undirected graph with nodes. If two different people know each other, we connect an undirected edge between their corresponding nodes and assign it a positive weight . The smaller is, the closer their relationship is. We measure the closeness between two people and 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 and , that is, these nodes have a certain degree of importance for the connection between and . We can measure a node’s importance in the social network by counting the number of shortest paths that pass through a node . Considering that there may be multiple shortest paths between two nodes and , we modify the definition of importance as follows: let denote the number of different shortest paths from to , and let denote the number of shortest paths from to that pass through . Then define:
as the importance of node in the social network. To make and 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 of the testdata, .
- For of the testdata, , each edge weight is a positive integer and .
- The graph is guaranteed to be connected, and the number of shortest paths between any two nodes does not exceed .
Input Format
The first line contains two integers and , the number of nodes and undirected edges in the social network.
In the undirected graph, all nodes are numbered from to .
Each of the next lines contains three integers describing an undirected edge connecting nodes and with weight .
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 lines, each containing a real number rounded to decimal places. The real number on the -th line represents the importance of node 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 , only the shortest paths from node to node and from node to node pass through node . Moreover, there are shortest paths between node and node . Therefore, by the definition, the importance of node is . Due to the symmetry of the graph, the importance of the other three nodes is also .
Translated by ChatGPT 5
京公网安备 11011102002149号