forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Find_Marble.cpp
43 lines (42 loc) · 1009 Bytes
/
B_Find_Marble.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
#define mod 1000000007
#define lli long long int
#define endl '\n'
#define deb(x) cout << #x << '=' << x << '\n'
#define deb2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y << '\n'
#define deb3(x, y, z) cout << #x << '=' << x << ',' << #y << '=' << y << ',' << #z << '=' << z << '\n'
#define deb4(x, y, z, w) cout << #x << '=' << x << ',' << #y << '=' << y << ',' << #z << '=' << z << ',' << #w << '=' << w << '\n'
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, s, t;
cin >> n >> s >> t;
vector<int> v1(n + 1);
for (int i = 1; i < n + 1; i++)
cin >> v1[i];
int curr = s;
int check = n + 1;
bool find = false;
int ans = -1;
while (check--)
{
ans++;
if (t == curr)
{
find = true;
break;
}
curr = v1[curr];
}
if (find)
{
cout << ans;
}
else
{
cout << -1;
}
return 0;
}