Submission
Status:
PPPPPPPPPP
Score: 100
User: Winzzwz
Problemset: ส่งต่อ
Language: cpp
Time: 0.002 second
Submitted On: 2025-03-09 12:25:41
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n,s,t[1010],mark[1010],cnt = 1;
queue <int> qu;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> s;
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
qu.push(s);
while (!qu.empty()) {
int top = qu.front(); qu.pop();
if (t[top] && mark[t[top]] == 0) {
mark[t[top]] = 1;
qu.push(t[top]);
cnt++;
}
}
cout << cnt;
return 0;
}