Problem C
Game Strategy
Alice and Bob are playing a board game. The board is divided
into positions labeled
-
Alice makes a choice. Depending on the current position, she has different options, where each option is a set of positions. Alice chooses one set
among the available sets of positions. -
Bob makes a choice. His choice is one position
from the set that Alice chose in step 1. Bob moves the gamepiece to position , which is the position for the start of the next round.
Prior to the first round, each player independently selects one of the positions and reveals it at the start of the game. Bob’s position is where the game starts. Alice wins the game if she can force Bob to move the gamepiece to the position she has chosen. To make things interesting, they have decided that Bob will pay Alice a certain amount if he loses, but Alice must pay Bob a certain amount after every round. The game now ends if Alice’s position is reached or when Alice runs out of cash.
Both Alice and Bob play optimally: Alice will always choose an option that will lead to her winning the game, if this is possible, and Bob will always try to prevent Alice from winning.
For all possible start and end positions, Alice would like you to determine whether she can win the game and if so, how many rounds it will take.
Input
The input consists of a single test case. The first line
contains the number of positions
Output
For each position
Sample Input 1 | Sample Output 1 |
---|---|
2 2 ab b 1 b |
0 1 -1 0 |
Sample Input 2 | Sample Output 2 |
---|---|
3 1 b 2 b a 2 ab ac |
0 1 -1 1 0 -1 2 2 0 |