编程介的小学生 2017-08-27 10:22 采纳率: 20.5%
浏览 1598
已采纳

Alice and Bob

"Alice and Bob take turns choosing one of the numbers, and replace it with one of its positive factor but not itself. The one who makes the product of all numbers become 1 wins."

Alice and Bob meet again this week, they played the game as description above last week. But Bob is so stupid that he had to spend lots of time on picking up "one of the number's factor but not itself". So Alice puts up a new game which needn't deal with the number. Here comes the problem.

Alice and Bob take turns choosing one of the toys to move on the map, at the beginning of the game, they have M toys to choose. At each turn, they must choose one toy on the map, and make it move, the toy which the player chooses to move would not stay in the same place as last turn. There are N places on the map, naming 1, 2, 3, ..., N-1, N, the initial places of M toys are among these 1, 2, 3, ..., N-1 places, except the place N. Each of the M toys has a distinct initial place. If two different toys arrive at the same place, the operation is also valid. Finally, the place N is the terminal place. After the toy is moved to the place N, it will be eliminated from the map. Of course the eliminated toys cannot be moved again. And notice that we assume Alice takes the first turn. The one who has no toys to move is the loser. Notice that even there are toys remaining on the map, it has the possibility that the player cannot move any toys forward. The player would lose in this situation. See the Case 2 in the Sample Input section.

The map is assured to be a directed acyclic graph and the map would not change in the game. As the one of the cleverest programmers in the world, you are asked to place the toys on the map (That means that you decide the value of M and the initial places of these M toys). So, you want to know that who will win in your arrangement, assuming both of them are clever enough to play this game. The number of the edges between places is no more than 100000.

Input

There are multiple test cases. Each case begins with an integer N (1 ≤ N ≤ 10000) in one line. In the following N-1 lines, ith(1≤ i ≤N-1) line describe the places where place naming i can arrive. "Ci p1 p2 ... pCi" implies that the number of places i can arrive totally Ci places, p1, p2, ..., pCi respectively.

Then input comes with an integer Q in one line. In the fowllowing Q(1≤ Q ≤ 100) lines, it containes an integer M(1≤ M ≤ N-1) and the name of M distinct places, which are the initial places of M toys at the beginning of the game.
There would not be any empty lines between cases.

Output

For each case, the output begins with "Case c:" in one line, where c indicates the case number. Then print exactly one line for each query in each test case. If the winner would be Alice, print "Alice", otherwise print "Bob".

Sample Input

4
2 2 3
1 4
1 4
3
1 1
1 2
2 1 2
4
2 2 3
1 4
0
2
1 3
2 3 1
10
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
3
1 1
5 1 2 3 4 5
9 1 2 3 4 5 6 7 8 9
Sample Output

Case 1:
Bob
Alice
Alice
Case 2:
Bob
Alice
Case 3:
Alice
Alice
Alice

  • 写回答

1条回答

  • threenewbee 2017-09-10 15:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?