PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000053. Con đường trên trời (Heavenly Road)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Con đường trên trời (Heavenly Road)
Heavenly Road
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
There are attractions and directed railway routes. Every route has fun value and positive fare . Find the maximum sum-of-fun divided by sum-of-fares among directed cycles, or print -1 if none exists.
Input
First line ; then lines .
Output
Print -1 if there is no directed cycle; otherwise the maximum ratio rounded to one decimal place.
Subtasks
- Subtask 1 (20 points): , ; ; ; parallel directed edges allowed; finite answer at most .
- Subtask 2 (30 points): , ; ; ; parallel directed edges allowed; finite answer at most .
- Subtask 3 (50 points): , ; ; ; parallel directed edges allowed; finite answer at most .
Examples
Input
3 3
1 2 7 2
2 3 9 3
3 1 8 3
Output
3.0
Explanation
The only cycle is . It has total fun and total expense , giving ratio . Rounded to one decimal, the output is 3.0.