#P1730. 最小密度路径
最小密度路径
Description
Given a weighted directed acyclic graph (DAG) with vertices and edges, followed by queries. Each query consists of two vertices and . Compute a path from to with minimum density, where density is defined as the sum of edge weights along the path divided by the number of edges.
Input Format
The first line contains two integers and . Each of the next lines contains three integers , indicating there is a directed edge from to with weight . The next line contains an integer . Each of the next lines contains a query with two vertices and , as described.
Output Format
For each query, output one line containing the density of the minimum-density path, rounded to decimal places. If no such path exists, output OMG!.
3 3
1 3 5
2 1 6
2 3 6
2
1 3
2 3
5.000
5.500
Hint
Constraints
, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号