Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
336 B
0
Indexable
Never
#include <fstream>
#include <iostream>
#include <string>
using namespace std;


int g(int a, int mas[], int i) {
	if (mas[i] == 1) {
		return i;
	}
	return g(a, mas, mas[i]);
}

int main()
{
	int n, a = 0;
	cin >> n;
	int mas[1000];
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
	}
	cout << g(a, mas, 0) + 1;
}