#P1730. 最小密度路径

最小密度路径

Description

Given a weighted directed acyclic graph (DAG) with NN vertices and MM edges, followed by QQ queries. Each query consists of two vertices XX and YY. Compute a path from XX to YY 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 NN and MM. Each of the next MM lines contains three integers A,B,WA, B, W, indicating there is a directed edge from AA to BB with weight WW. The next line contains an integer QQ. Each of the next QQ lines contains a query with two vertices XX and YY, as described.

Output Format

For each query, output one line containing the density of the minimum-density path, rounded to 33 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

1N501 \le N \le 50, 1M10001 \le M \le 1000, 1W1051 \le W \le 10^5, 1Q1051 \le Q \le 10^5.

Translated by ChatGPT 5