Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- #include <utility>
- #include <cstdlib>
- using namespace std;
- #define MAX 10001
- int inside[MAX], outside[MAX], changes[MAX];
- void main( void )
- {
- int n, m, x, k = 0;
- cin >> n >> m;
- for (int i = 0; i < m; i++)
- {
- cin >> inside[i] >> outside[i] >> changes[i];
- inside[i]--;
- outside[i]--;
- }
- vector<int> L(n, INT_MIN), p(n, -1), way;
- L[0] = 0;
- for (int i = 0; i < n; i++)
- {
- x = -1;
- for (int j = 0; j < m; j++)
- if (L[inside[j]] > INT_MIN &&
- L[outside[j]] < L[inside[j]] + changes[j])
- {
- L[outside[j]] = L[inside[j]] + changes[j];
- p[outside[j]] = inside[j];
- x = 1;
- }
- }
- for (int i = n - 1; i != -1; i = p[i])
- {
- k++;
- way.push_back(i);
- if (k > n)
- break;
- }
- if (L[n - 1] == INT_MIN)
- cout << ":(" << endl;
- else if (x != -1 && (way.back() !=0 || way.front() != n - 1 || k > n))
- cout << ":)" << endl;
- else
- cout << L[n - 1] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement