Rock Paper Scissors
Problem Description
N children (numbered 0, 1, 2, …, N-1) play Rock-Paper-Scissors.
One of them is the referee, and the rest are divided into three groups (some groups may be empty).
- The first group can only play Rock.
- The second group can only play Scissors.
- The third group can only play Paper.
The referee can use any gesture.
You do not know who the referee is, nor how the children are grouped.
The game proceeds for M rounds. In each round, two children are chosen to play.
You are told the outcome (win, lose, or draw) but not the specific gestures used.
After the game, can you deduce who the referee is?
If yes, after which round can you first determine the referee?
Input Format
The input may contain multiple test cases.
For each test case:
- The first line contains two integers N and M.
- The next M lines each contain two integers a, b with a symbol (>, =, <) in between, representing the outcome of a round:
- a > b means a wins.
- a = b means a draw.
- a < b means a loses.
Output Format
For each test case, output one line:
- If exactly one person can be the referee, output
Player x can be determined to be the judge after y lines, where x is the referee's number and y is the earliest round number (1-indexed) after which you can be sure. - If more than one person could be the referee, output
Can not determine. - If it is impossible for there to be exactly one referee (either no referee or more than one referee is forced), output
Impossible.
See the sample for exact format.
Data Range
1 ≤ N ≤ 500
0 ≤ M ≤ 2000
Input Sample:
3 3
0<1
1<2
2<0
3 5
0<1
0>1
1<2
1>2
0<2
4 4
0<1
0>1
2<3
2>3
1 0
Output Sample:
Can not determine
Player 1 can be determined to be the judge after 4 lines
Impossible
Player 0 can be determined to be the judge after 0 lines
Comments