当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4650:Minimum Average Weight Path

题目描述
In mathematics, a graph is a representation of a set of objects where some pairs of the objects are connected by links. The interconnected objects are represented by mathematical abstractions called vertices, and the links that connect some pairs of vertices are called edges. A path in a graph is a sequence of vertices, and for any 2 adjacent u, v, there is a edge from u to v in graph. A path contains at least one edge. In the graph in Sample 2, {3, 3, 2, 2} can form a path from 3 to 2.

One of the common problem is to find the shortest path between two certain vertices, or all of them. They've been well studied as the single source shortest path problem (SSSP) and the all pairs shortest paths problem (APSP).

In this problem, we'll provide you a derivation analogous to APSP. You've been given a directed graph with positive or negative edge weights. We define the average weight of a path, as the sum of the edge weights divide the edges number of path. Now you need to find the minimum average weight between all pairs of vertices (APMAWP).

输入解释
Muiltcases. The first line contains two integer n, m, (1 ≤ n ≤ 102, 1 ≤ m ≤ 104 ) the number of the vertices and the number of the edges.

The next m lines, each line contains three intergers u, v, w, representing a directed edge from u to v with weight w. (|w| ≤ 103)

There is no multi-edge. It can contain self-loops.

输出解释
A n × n matrix representing the APMAWP. The j's element of the i's row represents the minimum average weight of all the paths from vertex i to vertex j. If no such path exists, you need to output "NO" instead (DO NOT output quote please). For each real number, you need to keep exactly 3 digits after digit point.

输入样例
4 4
2 1 2
1 3 -8
2 4 -6
4 3 1
5 8
3 3 735
2 1 946
4 2 276
2 2 -990
3 2 -162
4 4 -18
3 5 783
5 5 -156
输出样例
NO NO -8.000 NO
2.000 NO -3.000 -6.000
NO NO NO NO
NO NO 1.000 NO
NO NO NO NO NO
-990.000 -990.000 NO NO NO
-990.000 -990.000 735.000 NO -156.000
-990.000 -990.000 NO -18.000 NO
NO NO NO NO -156.000
来自杭电HDUOJ的附加信息
Recommend zhuyuanchen520

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4650

最后修改于 2020-10-25T23:15:29+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 32768/32768K(Java/Others)