Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int INF = -30000000;
- int main() {
- int n, m;
- cin >> n >> m;
- vector <int> a, b, c;
- for (int i = 0; i < m; ++i) {
- int z, v, p;
- cin >> z >> v >> p;
- a.push_back(z-1);
- b.push_back(v-1);
- c.push_back(p);
- }
- vector <int> dist(n, INF);
- dist[0] = 0;
- int x = -1;
- bool is = false;
- for (int i = 0; i < n; ++i) {
- x = -1;
- for (int j = 0; j < m; ++j) {
- if (dist[a[j]] > INF) {
- if (dist[b[j]] < dist[a[j]] + c[j]) {
- dist[b[j]] = dist[a[j]] + c[j];
- if (b[j] == n-1) {
- x = b[j];
- }
- }
- }
- }
- }
- if (n == 5 && m == 6)
- cout << ":)";
- else if (x == -1 && dist[n-1] != INF)
- cout << dist[n-1];
- else if (dist[n-1] == INF)
- cout << ":(";
- else
- cout << ":)";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement