Hide

Problem J
Deterministic Finite Automata - Is a Finite Language?

Accepted submissions to this problem will be granted a score of 12
Languages en is

You are given a deterministic finite automaton that accepts the language L. You should output whether L is a finite language.

Input

The input contains the description of a deterministic finite automaton.

The first line contains four positive integers n, c, s, and f, where n is the number of states, c is the size of the alphabet, s is the initial state, and f is the number of final states. The second line consists of a string Σ=Σ1Σ2Σc of c distinct symbols, each of which is a lowercase english character. The third line consists of f distinct positive integers, the set of final states. Then n lines follow, each with c positive integers, describing the symbol table. The j-th integer on the i-th of those lines represents the state transitioned to from state i upon reading Σj.

Each state is an integer between 1 and n. It is guaranteed that 1n10000, 1sn, and 0fn.

Output

Output finite if L is a finite language, otherwise output infinite.

Sample Input 1 Sample Output 1
4 2 2 2
ab
2 4
2 3
3 2
3 3
1 2
infinite
Sample Input 2 Sample Output 2
4 4 1 2
acgt
1 2
2 2 2 2
3 3 3 3
4 4 3 4
3 3 3 4
finite
Hide

Please log in to submit a solution to this problem

Log in