Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define db long double
  4. #define x first
  5. #define y second
  6. #define mp make_pair
  7. #define pb push_back
  8. #define all(a) a.begin(), a.end()
  9.  
  10. using namespace std;
  11.  
  12. struct Data {
  13. int a, b, c, d, e;
  14. };
  15.  
  16. int main(){
  17. #ifdef LOCAL
  18. freopen("F_input.txt", "r", stdin);
  19. //freopen("F_output.txt", "w", stdout);
  20. #endif
  21. ios_base::sync_with_stdio(0);
  22. cin.tie(0);
  23. int n, x0;
  24. cin >> n >> x0;
  25. vector <Data> a;
  26. for (int i = 0; i < n; i++) {
  27. int aa, b, c, d, e;
  28. cin >> aa >> b >> c >> d >> e;
  29. c--, e--;
  30. a.push_back({aa, b, c, d, e});
  31. }
  32. int v = 0, x = x0;
  33. int cnt = 0;
  34. map <pair <int, int>, bool> was;
  35. while (cnt < 1e6 && v != n) {
  36. if (x == a[v].a) {
  37. x += a[v].b;
  38. v = a[v].c;
  39. } else {
  40. x += a[v].d;
  41. v = a[v].e;
  42. }
  43. cnt++;
  44. }
  45. if (cnt == 1e6) {
  46. cout << "-1\n";
  47. return 0;
  48. }
  49. cout << cnt << "\n";
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement