|
||||||||||
Minimum Average Weight PathTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 451 Accepted Submission(s): 221 Problem Description 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). Input 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. Output 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. Sample Input
Sample Output
Source | ||||||||||
|