ROIM - Boa viagem, Roim


Computer Engineering student Roim is getting ready for a trip to Mexico. For that, he has studied the airplane network, so he knows the details of all R regular flights currently in operation on all of the N available airports. Unfortunately, one of his school mates is very annoying and keeps saying the same stuff to him all the time. 

To solve that issue, he will organize two different flight plans: one for the team and one for the annoying guy. The condition is that the flight plans may not contain the same flight (note that it is possible for both to pass through the same airport, and that the same flight may not be used by both even if the times are different). As this may not be possible using only regular flights, he has also considered using some of the C flights chartered by travel agencies, but he'd like to keep those to a minimum as they usually suffer from large delays. Of course, as long as the least number of chartered flights is picked, Roim will pick the plans with the least total cost (defined as the sum of the costs of all flights used).

Input

The input consists of several test cases. On the first line of a test case are three integers N (2 ≤ N ≤ 225), R and C (0 ≤ R+C ≤ N(N-1)/2) separated by spaces. The starting airport is 0, and the destination is N-1.

The next R lines contain integers a, b (0 ≤ a, b ≤ N-1), c (1 ≤ c ≤ 100), meaning that there exists a one-way regular flight between airports a and b, with cost c. The following C lines give details for chartered flights in the same manner. There is a blank line at the end of each test case. The last test case is followed by a line containing three zeros.

You may assume that any pair of cities is only connected in at most a single direction by a single flight.

Output

If it is possible to make the plans, print two integers separated by spaces. The first should be the minimum amount of chartered flights used, and the second is the total cost of the solution.

If it's impossible that both the team and the guy get to their destination, print "Boa viagem, Roim" instead.

Example

Input:
4 5 0
0 1 1
1 3 5
0 2 5
1 2 1
2 3 1

4 4 1
0 1 2
1 3 2
0 2 2
1 2 1
2 3 2

2 1 0
0 1 10

0 0 0

Output: 0 12
1 8
Boa viagem, Roim

hide comments
Fernando Fonseca [ITA]: 2015-05-02 08:11:14

As min_25 pointed out, something weird happened with TL adjustment and none of the solutions that had passed on Pyramid were passing on Cube (I guess SPOJ should have added some sort of sanity check on TL readjustment).

In normal conditions I'd say 0.027 was impossible, but kudos to LeBron for proving me wrong with his crazily optimized code. However, given that no one from Bubble Cup actually bothered to solve this problem in the low TL settings, I presume they intended for looser ones. In a 1-month contest strict TL is probably OK, but this was just too strict...

LeBron: 2015-05-02 00:34:28

@RandomUsername
Actually I have no idea what was the goal of problemsetter. For some problems main part is finding intended algorithms; and some other tasks are focused on writing good solutions or implementing some part of solution in a good way (I've seen special contests in some trainings camps - "Catch me!", where like all 10 or 11 problems were based on cache optimizations, and "Big data contest" with all tasks having enormous i/o size). I remember problem RNG from one of previous CodeChef contests, where my first solution with intended asymptotic was working ~ 3 minutes. It was some trash, but it had intended asymptotic :) Now when people said that original TL for this task was something like 2 hours... :D I understand that maybe author didn't wanted us to write any good solution. But then all this situation looks very unnatural for me - this task looks too easy for Round 2. I thought that goal of this task was - "here is very simple problem with a strict TL, you have a lot of time to write a good solution".
In case if TL will be rised - it is great experience for me to solve this task with stricter TL; but it will be second fail of BC orgs in a row - using a problem for a contest without proper checking of it.

RandomUsername: 2015-05-02 00:12:32

@LeBron
I don't think the goal of any problem is to enforce silly optimizations, fast input, and stuff like that. There's no point in bullying someone who uses a desired algorithm, with the desired asymptotic complexity and a reasonable constant factor.

If you used a better algorithm, then disregard what I said. But in case you just spent hours optimizing the same code, I still think the TL should be increased.

LeBron: 2015-05-02 00:02:27

@Min_25
Come on, I finally managed to solve it with 0.027 seconds. As you can see, it is solvable; therefore it will be stupid to decrease TL - people have full month to make their solutions fast enough) When I started this problem I actually believed that low TL was set intentionally to make it more interesting)

Min_25: 2015-05-01 23:27:13

@bubblecup
The time limit of this problem was *automatically* changed from 3.00 sec to 0.027 sec (due to the Cluster change).
So, it was not set by the problem author.

Perhaps, it should be set to around 0.300 sec.

Last edit: 2015-05-01 23:33:02
LeBron: 2015-05-01 19:17:58

I guess TL is OK, looks like author set this TL to prevent stupid solutions from passing (and making TL challenging was his goal, because otherwise problem becomes too easy).

Upd. OK, time limit is actually quite low :)

Last edit: 2015-05-01 21:58:56
RandomUsername: 2015-05-01 17:53:59

C++ scanf can't read the whole input file in time, are you sure about the time limit?

fcdkbear: 2015-05-01 17:10:16

Time limit is definitely too strict. Are you sure it must be 0.027 seconds?

hunguk: 2015-05-01 12:41:51

Time limit seems too strict

Radhakrishnan Venkataramani: 2012-08-23 04:24:06

Suppose if The team used an airline at some time t, is the another guy allowed to use the same airline at later time ?

author: in this case both plans would contain the same flight, so it is not allowed.

Last edit: 2012-06-18 03:43:18

Added by:Fernando Fonseca [ITA]
Date:2012-06-13
Time limit:0.300s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64