#BF0000024. Trò chơi năng lượng (XYZZY)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trò chơi năng lượng (XYZZY)
XYZZY
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A game has rooms numbered through . You begin in room with energy and aim to enter room . Entering room adds its energy value ; one-way doorways connect rooms. Revisited rooms contribute their energy every time. Energy must remain strictly positive at each step, otherwise the player dies. Start and finish rooms have energy zero. Determine whether the game is winnable.
Input
The first line contains . For each room , one record gives its energy , outgoing-door count , and destination room indices.
Output
Print winnable if the final room can be entered with strictly positive energy throughout the walk, or hopeless otherwise.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; doorways are directed, destination in .
-
Subtask 2 (30 points): ; ; ; ; doorways are directed, destination in .
-
Subtask 3 (50 points): ; ; ; ; doorways are directed, destination in .
Examples
Input
5
0 1 2
-60 1 3
-60 1 4
20 1 5
0 0
Output
hopeless
Explanation
Entering room leaves energy; entering room would reduce it to , immediately losing.