编程介的小学生 2017-04-13 05:39 采纳率: 20.5%
浏览 810
已采纳

Board Games

You have been hired by the quality control division of a world famous board game company. Their creative and design division comes up, on a daily basis, with great ideas for board games, but sometimes the scoring of the proposed games does not match the story board or leads the player to impossible or undesirable situations.

Most of the games this company produces can be described loosely as race games. Race games are games where the players need to go from an initial square to a final square, performing along the way, a series of moves, gaining or losing score points for each of those moves. Moves can be influenced by player's decisions, drawing of cards, rolling of dices, etc.

Your task is to check the description of a given game, stating the lowest possible score, or if it can lead to an infinitely high (there's no way the player can win the game), or to an infinitely low score.

Input

A positive integer P in a single line followed by a sequence of P game descriptions. The first line of the game description contains a positive integer N not greater than 300, indicating the number of squares in the game. The second line contains two non-negative integers, I and F, defining the initial and final squares for this game, where I and F are lesser than N. The third line contains an integer M, indicating the number of possible moves of the game. The following M lines describe all the possible moves of the game. Each line, describing one possible move, consists of three integers, respectively, the initial square and final square of the move, in the range [0, N-1],and the corresponding score.

Output

The output consists of a single line with an integer, indicating the lowest possible score for the proposed game. If the scores are infinitely high or low then your program should output infinity.

Sample Input

2
4
0 3
4
0 1 5
0 2 7
2 1 -3
1 3 2
4
0 3
3
0 1 5
0 2 7
2 1 -3
Sample Output

6
infinity

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料