Problem Statement | |||||||||||||
We have a program segment and want to analyze the control flow through it.
We have already replaced the actual code with simpler code that captures just
the control logic. The code we want to analyze consists of a sequence of
statements in which each statement is one of the following two types:
Execution of the program segment starts at the first statement (statement 0) and concludes when it reaches a RETURN statement. We call such a sequence an "execution path." In order to optimize the code, we want to find the smallest loop in the program segment that can be executed. A loop is defined to be a set of statements such that
| |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | code will contain between 1 and 50 elements inclusive. | ||||||||||||
- | Each element of code will be one of the two forms above. | ||||||||||||
- | Each RETURN statement has no spaces. | ||||||||||||
- | Each IF statement has exactly 3 spaces. | ||||||||||||
- | Each target1 and target2 will be an integer with no extraneous leading zeroes. | ||||||||||||
- | Each target1 and target2 will be between 0 and n-1 inclusive, where n is the number of elements in code. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|