#P6895. [ICPC 2014 WF] Game Strategy

[ICPC 2014 WF] Game Strategy

题目描述

Alice and Bob are playing a board game. The board is divided into positions labeled a,b,c,d,a, b, c, d, \dots and the players use a gamepiece to mark the current position. Each round of the game consists of two steps:

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 SS among the available sets of positions.

Bob makes a choice. His choice is one position pp from the set SS that Alice chose in step 1. Bob moves the gamepiece to position pp, 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.

输入格式

The input consists of a single test case. The first line contains the number of positions nn (1n251 \leq n \leq 25). The nn positions are labeled using the first nn letters of the English alphabet in lowercase. The rest of the test case consists of nn lines, one for each position pp, in alphabetical order. The line for position pp contains the options available to Alice in position pp. It starts with the number of options mm (1m<2n1 \leq m < 2^ n), which is followed by mm distinct strings, one for each option. Each string contains the positions available to Bob if Alice chooses that option. The string has at least 11 character, the characters (which correspond to valid board positions) are in alphabetical order, and no characters are duplicated. The total number of options for the test case is at most 10610^6.

输出格式

For each position pp in alphabetical order, display one line. In that line, for each position qq in alphabetical order display the minimal number of rounds in which Alice can be guaranteed to arrive at position qq when starting the game in position pp, or 1-1 if Alice cannot be guaranteed to reach qq from pp.

2
2 ab b
1 b

0 1 
-1 0

3
1 b
2 b a
2 ab ac

0 1 -1 
1 0 -1 
2 2 0

提示

Time limit: 5000 ms, Memory limit: 1048576 kB.

International Collegiate Programming Contest (ACM-ICPC) World Finals 2014