F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Collecting Forest Wildlife

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 131    Accepted Submission(s): 8


Problem Description
Volunteers from the World Wildlife Foundation (WWF) have arrived in Springfield in a WWF truck.
They are collecting endangered animals living in the nearby Gump Forest, and are asking Lisa for help.
The WWF volunteers have given Lisa a map of the Gump Forest. The forest contains a number of clearings, and trails connecting the clearings. Different types of endangered animals live on each trail, no animals live in the clearings. Every trail must have at least one animal. Two trails connected to the same clearing cannot have the same animal.
Trails in the Gump Forest are narrow, so the WWF truck can only turn once it reaches the end of the trail and reaches a clearing. Exactly one endangered animal must be collected each time the truck drives along a trail. A trail may be traveled many times to pick up multiple animals.
TheWWF truck is filled with a number of cages, where each cage is designed for a single endangered species. Unfortunately, the truck is so filled with cages that the cages can only be filled in a certain order. Lisa has been asked to go with the WWF volunteers in their truck and guide the truck through
the Gump Forest and fill all the cages in the truck. The truck starts at the clearing at the entrance, goes through the forest, and returns to the entrance.
 

Input
Animals are given as words(lowercases). Clearings are given as numbers. There may be up to 500 clearings.
Clearing 0 is always the entrance to Gump Forest.
The input begins with the Gump Forest trail map. Each line describes a trail between two clearings as a pair of numbers, followed by a list of animals living on the trail. Remaining lines begain with list of animals to be collected, in the order they are to be collected.
 

Output
For each list of animals to be collected, your program should output the successful path through the Gump Forest as a sequence of numbers in the order clearings are visited, starting and ending with 0. If multiple successful paths are possible, print any successful path. If there is no successful path
through the Gump Forest that can fill up the truck and return it to the entrance, your program should output ¡±Failed¡± for that list.
Hint: Don¡¯t try to solve the problem in a brute-force manner by enumerating all possible paths through Gump Forest. (It will take too long.)
 

Sample Input
0 1 puma 1 2 frog puma puma puma frog frog puma 1 0 puma lynx 1 2 vole 2 0 toad toad vole lynx puma lynx toad puma lynx
 

Sample Output
0 1 0 0 1 2 1 0 0 2 1 0 1 0 Failed
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 19:55:36, Gzip enabled