Website Summary Files Commits Branches @commit @diff @stats
path: root / Week05 / Exercise12.cpp
blob: eac5f0890669307b89d886ca957861ba96f521ea (plain) (blame)
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
#include <iostream>

int main() {
    const unsigned int SIZE = 20;

    unsigned short indecies[SIZE];
    bool visited[SIZE];
    for (unsigned int i = 0; i < SIZE; i++) {
        std::cin >> indecies[i];
        visited[i] = false;
    }

    unsigned int current_index = 0, jumps = 0;
    while (current_index != SIZE - 1 && !visited[current_index]) {
        visited[current_index] = true;
        current_index = indecies[current_index];
        jumps++;
    }

    if (current_index != SIZE - 1)
        std::cout << "Infinity" << std::endl;
    else
        std::cout << jumps << std::endl;

    return 0;
}