PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000405. Đường đi đẹp nhất (Beautiful Path)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường đi đẹp nhất (Beautiful Path)
Beautiful Path
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A directed graph has vertices numbered 1 through and edges. Edge runs from to (), with positive integer beauty and cost . Parallel edges are allowed. Choose a path from 1 to and divide its total beauty by its total cost. Find the greatest achievable ratio; at least one such path exists.
Input
The first line contains integers . Each of the next lines contains , the tail, head, beauty and cost of edge , in order.
Output
Print the maximum ratio as a real number. The absolute or relative error must not exceed .
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; for every . A path from 1 to exists.
- Subtask 2 (30 points): ; ; ; ; ; for every . A path from 1 to exists.
- Subtask 3 (50 points): ; ; ; ; ; for every . A path from 1 to exists.
Examples
Input
3 3
1 2 2 1
2 3 4 3
1 3 2 3
Output
1.500000000000
Explanation
The path has beauty , cost , ratio . The direct path has ratio . Thus the maximum is .