PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000048. Chênh lệch tỷ giá II (Arbitrage II)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chênh lệch tỷ giá II (Arbitrage II)
Arbitrage II
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given named currencies and directed, commission-free exchange rates, decide whether some sequence of exchanges starts and ends in the same currency with a net gain.
Input
First line , then currency names, then and lines from rate to.
Output
Print Yes if arbitrage is possible, otherwise No.
Subtasks
- Subtask 1 (20 points): , ; Currency names contain 1 to 30 non-whitespace characters; every rate .
- Subtask 2 (30 points): , ; Currency names contain 1 to 30 non-whitespace characters; every rate .
- Subtask 3 (50 points): , ; Currency names contain 1 to 30 non-whitespace characters; every rate .
Examples
Input
3
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar
Output
Yes
Explanation
Starting with 1 US dollar, the conversions yield US dollars. This exceeds the starting amount, so arbitrage is possible and the output is Yes.