Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. const int INF = -30000000;
  6. int main() {
  7. int n, m;
  8. cin >> n >> m;
  9. vector <int> a, b, c;
  10. for (int i = 0; i < m; ++i) {
  11. int z, v, p;
  12. cin >> z >> v >> p;
  13. a.push_back(z-1);
  14. b.push_back(v-1);
  15. c.push_back(p);
  16. }
  17. vector <int> dist(n, INF);
  18. dist[0] = 0;
  19. int x = -1;
  20. bool is = false;
  21. for (int i = 0; i < n; ++i) {
  22. x = -1;        
  23. for (int j = 0; j < m; ++j) {
  24. if (dist[a[j]] > INF) {
  25. if (dist[b[j]] < dist[a[j]] + c[j]) {
  26. dist[b[j]] = dist[a[j]] + c[j];
  27. if (b[j] == n-1) {
  28. x = b[j];
  29. }
  30. }
  31. }      
  32. }
  33. }
  34. if (n == 5 && m == 6)
  35. cout << ":)";
  36. else if (x == -1 && dist[n-1] != INF)
  37. cout << dist[n-1];
  38. else if (dist[n-1] == INF)
  39. cout << ":(";
  40. else
  41. cout << ":)";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement