#include using namespace std; struct cost{ int to; bool direct; double price; cost(){} cost(int _to, bool _direct, double _price){ to = _to; direct = _direct; price = _price; } }; const int maxn = 1e4 + 10; map currency; vector v[maxn]; int n, used[maxn], used1[maxn], used2[maxn], X1; bool infmoney[maxn]; double money[maxn]; inline void get_num_from_map(int &num, string &s){ if(currency.find(s) == currency.end()) currency[s] = currency.size() + 1; num = currency[s]; } void make_component_profit(int ver){ used2[ver] = 1; infmoney[ver] = true; //if() for (auto nb: v[ver]) if (!used2[nb.to]) make_component_profit(nb.to); } void DFS(int ver){ used[ver] = 1; used1[ver] = 1; for (auto nb: v[ver]){ double curmoney; if (!used1[nb.to]){ curmoney = money[nb.to]; money[nb.to] = (nb.direct == true)? money[ver]*nb.price: money[ver]/nb.price; DFS(nb.to); money[nb.to] = curmoney; } else{ double curmoney = (nb.direct == true)? money[ver]*nb.price: money[ver]/nb.price; if (curmoney > money[nb.to]){ cout << "YES\n"; exit(0); } } } used1[ver] = 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i < n; ++i){ string s1, s2; double price; cin >> s1 >> s2 >> price; int n1, n2; get_num_from_map(n1, s1); get_num_from_map(n2, s2); v[n1].push_back(cost(n2, true, price)); v[n2].push_back(cost(n1, false, price)); } X1 = currency["BGN"]; money[X1] = 1; DFS(1); cout << "NO\n"; return 0; }