33 lines
543 B
C++
33 lines
543 B
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int main() {
|
|
ios_base::sync_with_stdio(false);
|
|
cin.tie(NULL);
|
|
freopen("search.inp", "r", stdin);
|
|
|
|
int n, x;
|
|
cin >> n >> x;
|
|
vector<int> a(n);
|
|
for (int &i : a)
|
|
cin >> i;
|
|
|
|
if (x - 1 > n || x < 0) {
|
|
cout << -1 << '\n';
|
|
return 0;
|
|
} else {
|
|
x = a[x - 1];
|
|
}
|
|
int cnt = 0;
|
|
for (int i = 0; i < n; i++) {
|
|
// cout << a[i] << '\n';
|
|
if (a[i] == x) {
|
|
cout << i + 1 << ' ';
|
|
cnt++;
|
|
}
|
|
}
|
|
cout << '\n';
|
|
cout << ((cnt == 0) ? -1 : cnt) << '\n';
|
|
}
|