XYZZY
Time limit1sMemory limit128 MB
Given rooms with energy values and one-way doors, decide if the player can reach room n from room 1 while energy stays above zero, where rooms may repeat.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, DFS
- Solved
- No attempts yet
Problem
ADVENT: /ad´vent/, n.
The prototypical computer adventure game, first designed by Will Crowther on the PDP-10 in the mid-1970s as an attempt at computer-refereed fantasy gaming, and expanded into a puzzle-oriented game by Don Woods at Stanford in 1976. (Woods had been one of the authors of INTERCAL.) Now better known as Adventure or Colossal Cave Adventure, but the TOPS-10 operating system permitted only six-letter filenames in uppercase. See also vadding, Zork, and Infocom.
It has recently been discovered how to run open-source software on the Y-Crate gaming device. A number of enterprising designers have developed Advent-style games for deployment on the Y-Crate. Your job is to test a number of these designs to see which are winnable.
Each game consists of a set of at most 100 rooms. One of the rooms is the start and one of the rooms is the finish. Each room has an energy value between -100 and 100. One-way doorways interconnect pairs of rooms.
The player begins in the start room with 100 energy points. She may pass through any doorway that connects the room she is in to another room, thus entering that other room. The energy value of the room she enters is added to her energy. This process continues until she wins by entering the finish room, or dies by running out of energy, or quits in frustration. The player may enter the same room several times, gaining its energy value each time.
The player dies the instant her energy drops to 0 or below, so she can keep moving only while her energy stays strictly positive. Determine whether it is possible for the player to reach the finish room.
Input
The input consists of several test cases. Each test case begins with , the number of rooms (at most 100). The rooms are numbered from (the start room) to (the finish room). The descriptions of the rooms follow. The description of room is given on one or more lines and contains:
- the energy value of room ,
- the number of doorways leaving room , and
- the list of rooms reachable through those doorways.
The start room and the finish room always have energy value . A line containing follows the last test case.
Output
For each test case, output a single line containing winnable if the player can reach the finish room, or hopeless otherwise.