#Lutece0586. max air city
max air city
Migrated from Lutece 586 max air city
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
MAX AIR CITY is an illusory city.Matters every day in this bustling city is happening. MAX AIR CITY is made up of regions (conveniently numbered from to ) but unfortunately is connected by unidirectional roads, however, to overcome the shortages, there can be multiple roads between any two regions.
Today, YAN leaves Tian all of a sudden because Tian has made a serious mistake. Tian is eager to find YAN.
He has to go to different regions to collect information in order to make a decision how should he take the next step.
Now, Tian has a list which indicates the regions he will reach. But he is not sure the order of visiting.
So once he has got to a region, he has to return home to analyse the next place to go to. Be careful that it takes time to prepare his leaving(such as have a meal,the call of nature). In other words, to travel from region to any other adjacent city , preparation would cost him of time to , and then time on the road.
Tian wants to find YAN as soon as possible even any piece of message about her, so he wants to use the least time to collect information. Luckily ,you are a good programmer and he is eager to ask for your help to calculate the minimum time that it may take him to find his YAN.
Input
The first line of the input contains an integer indicating the number of cases.
Each case contains lines. The first line contains integers separated by blank. () is the number of regions. () is the number of roads. indicates which region Tian’s home is in.
is number of regions that Tian has to reach. The second line is integers indicating the number of these regions.
Then a line with integers indicating the time that must be cost to prepare () .
The following lines each contains integers separated by a blank indicate that there is a road from to , and it would cost time .
All data will fit in a -bit integer.
Output
For each test case, output one line with an integer indicating the minimum time. Note that if Tian can’t visit all the regions or he can’t return home after any visiting, then output “Tumblerful” (without quotation).
Samples
2
3 4 1 2
2 3
5 5 5
1 2 3
2 3 5
3 1 7
1 3 4
2 1 1 1
2
2 3
1 2 3
51
Tumblerful
Note
- For the first case, Tian begins from his home at region , spend minutes to prepare. Then spend minutes on the road from region to region .Then he finished visiting and return ,spend minutes in region to prepare, via road get to region and spend minutes for preparation. Via road he return home. The next place is region . So he started at region spending minutes to prepare and then via road to finish his work of collecting information. The total time is ,the number in the brackets indicate the time for preparation.
- Huge input datas , scanf is recommended.
Resources
Sichuan University Programming Contest