PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000050. Giá Big Mac vòng quanh thế giới (Big Macs Around the World)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Giá Big Mac vòng quanh thế giới (Big Macs Around the World)
Big Macs Around the World
Source: BOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A Big Mac costs in country . Directed conversion multiplies its price by rate . Find the smallest achievable price in country through successive conversions; print 0 if a beneficial cycle drives the infimum to zero.
Input
First line ; then directed rates .
Output
Print 0 if there is no positive minimum; otherwise a real number with absolute or relative error at most .
Subtasks
- Subtask 1 (20 points): , ; , ; ; ; all countries are mutually reachable.
- Subtask 2 (30 points): , ; , ; ; ; all countries are mutually reachable.
- Subtask 3 (50 points): , ; , ; ; ; all countries are mutually reachable.
Examples
Input
3 4 60 1 2
1 2 0.20
1 3 5.00
3 2 0.50
2 1 5.00
Output
12.000000000000
Explanation
The direct exchange from country 1 to country 2 gives . Via country 3 it gives . The 1–2–1 cycle has product , so the minimum achievable price in country 2 is .