RS2D - Happiness at the lowest cost

no tags 

Rafael Phofo was a happy guy living with his best friend, Danilo Gheyi. They were so friends that they made a blood pact during their childhood. But Matheus Pheverso, the owner of the Infelicity Forest, a forest that Rafael and Danilo used to cross every day, didn't like to see them together. He always tried to separate them; a day he finally achieved his goal, making the two guys lost in two different points of his forest.

Rafael Phofo knew it wouldn't be hard to find his friend, because he had some RS2D (love notes), the money that Matheus Pheverso charged to let his visitors cross each street connecting two points of the forest.

But there was a problem: analyzing the map of the forest, Rafael realized that his amount of RS2D could be insufficient. So he called you, a great programmer and also his friend, to know if it's possible to find Danilo with that amount of RS2D. You need to write a program that determine the minimum amount of RS2D necessary. Consider that Rafael is in the position 1 of the forest and Danilo is in the position N.

Input

The input consists of several instances; the first line contains an integer K (1 ≤ K ≤ 20), the amount of instances. The first line of each instance contains two integers N and M (1 ≤ N ≤ 106, 1 ≤ M ≤ 106), the amount of points and the amount of streets in the forest, respectively. The next M lines contain three integers A, B and C (1 ≤ A ≤ N, 1 ≤ B ≤ N, 1 ≤ C ≤ 106), indicating a one-way street from point A to point B with cost C.

Output

For each instance output a sentence “Rafael will find his love for P RS2D.”, and P represents the minimum amount of RS2D that Rafael needs to caught Danilo.

Example

Input:
2
6 9
1 2 7
1 5 14
1 3 9
2 4 15
2 3 10
3 5 2
3 4 11
5 6 9
4 6 6
5 7
1 2 1
1 3 5
2 4 2
3 4 2
3 5 3
2 5 3
4 5 1

Output:
Rafael will find his love for 20 RS2D.
Rafael will find his love for 4 RS2D.

hide comments
Min_25: 2017-09-07 09:28:53

The constraints are misleading:
- max {sum N_i} is around 200000.
- max {sum M_i} is around 200000.

[Rampage] Blue.Mary: 2017-09-07 07:16:15

Agree with @tjm. The input test cases are actually very weak.

anonymous: 2017-03-22 16:02:56

The problem statement needs a general limit on input size. Currently there
seems to be a mismatch between input constraints and time limit. You can hardly
expect to even read worst case input, let alone process it within 0.1 sec.

This means that input test cases are actually very weak (with respect to input
constraints), this is quite unfortunate because you can't really tell if your
solution is good enough or not.

Last edit: 2017-03-22 17:23:14
sarthak mall: 2013-06-22 05:16:22

I am using O(v+e) algo...still getting TLE. and how could both the best submissions are more than the time constraints i.e 0.56 and 0.68 sec !!!

Mateus Dantas [ UFCG ]: 2012-02-26 05:40:50

Only for clarification... If there is a street from A to B, don't means that there is a street from B to A.. The Graph is directed, attention to this.

Josisvaldo Ferreira: 2012-02-26 05:40:50

Be careful with certain languages and the time limit, a simple n^2 and nlogn solution isn't enough... Try to optimize the solution!
optimize optimized dejikstra?

Last edit: 2012-02-27 13:22:26

Added by:Mateus Dantas [ UFCG ]
Date:2012-02-25
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Mateus Dantas