-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1162.cpp
44 lines (34 loc) · 1.06 KB
/
1162.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
struct Edge {
Edge * pred;
unsigned int end;
float rate, commission;
};
Edge * edges_node[101] {};
float this_balance[101] {};
bool hasProfit(float balance, unsigned currency) {
if (balance <= 0) return false;
if (this_balance[currency] != 0) return balance > this_balance[currency];
this_balance[currency] = balance;
for (Edge * edge = edges_node[currency]; edge != NULL; edge = edge->pred)
if (hasProfit((balance - edge->commission) * edge->rate, edge->end))
return true;
this_balance[currency] = 0;
return false;
}
int main() {
unsigned n, m, s;
float v;
cin >> n >> m >> s >> v;
unsigned a, b;
float r_ab, c_ab, r_ba, c_ba;
for (unsigned i = 0; i < m; ++i) {
cin >> a >> b >> r_ab >> c_ab >> r_ba >> c_ba;
edges_node[a] = new Edge {edges_node[a], b, r_ab, c_ab};
edges_node[b] = new Edge {edges_node[b], a, r_ba, c_ba};
}
if (hasProfit(v, s)) cout << "YES\n";
else cout << "NO\n";
return 0;
}