Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define db long double
- #define x first
- #define y second
- #define mp make_pair
- #define pb push_back
- #define all(a) a.begin(), a.end()
- using namespace std;
- struct Data {
- int a, b, c, d, e;
- };
- int main(){
- #ifdef LOCAL
- freopen("F_input.txt", "r", stdin);
- //freopen("F_output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n, x0;
- cin >> n >> x0;
- vector <Data> a;
- for (int i = 0; i < n; i++) {
- int aa, b, c, d, e;
- cin >> aa >> b >> c >> d >> e;
- c--, e--;
- a.push_back({aa, b, c, d, e});
- }
- int v = 0, x = x0;
- int cnt = 0;
- map <pair <int, int>, bool> was;
- while (cnt < 1e6 && v != n) {
- if (x == a[v].a) {
- x += a[v].b;
- v = a[v].c;
- } else {
- x += a[v].d;
- v = a[v].e;
- }
- cnt++;
- }
- if (cnt == 1e6) {
- cout << "-1\n";
- return 0;
- }
- cout << cnt << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement