THEWAR - Revenge of Arjuna


The Mahabharata is an epic narrative of the Kurukshetra War and the fates of the Kaurava and the Pandava princes. Arjuna was the 3rd of the Pandava brothers. He is considered the protagonist of the Mahabharata with Krishna. Abhimanyu was the son of Arjuna and Subhadra. Abhimanyu's story came to prominence on the 13th day of the war when he entered the powerful Chakravyuha battle formation of the Kaurava army. Drona had designed this configuration in order to capture Yudhishthira. On the side of the Pandavas, only Krishna and Arjuna were aware of the secret technique to break this seven-tier, defensive, spiral formation.

Seeing Yudhishthira's panic, Abhimanyu revealed that while he didn't know how to exit the formation, he would be able to break into it. A plan was formulated that the Pandava forces would enter the Chakravyuha after Abhimanyu, and shatter it from within. But as soon as Abhimanyu entered the Chakravyuha, Jayadratha stopped the four Pandavas from entering it. At last Abhimanyu was killed inside the Chakravyuha. The news of Abhimanyu's death reached his father Arjuna at the end of the day. Arjuna vowed to kill Jayadratha the very next day by sunset, and failing to do so, would commit suicide by self-immolation immediately. So Arjuna has to reach Jayadratha before sunset.

There are N spots in the Kauravas army numbered from 0 to N-1. Arjuna was always at spot 0 and Jayadratha was always at spot 1. He need to reach the spot '1' as soon as possible killing the soldiers of the army. The time to reach each spot is given in the form of N x N array. Also Arjuna had 'K' Divyastras (Divine arrow) which halves the time (only take half of what it normally would) to reach any spots. Arjuna was not allowed to use more than one Divyastras at same time. He may or may not use Divyastra. Find the smallest time in which Arjuna can reach Jayadratha.

Input

First line T the number of test cases. (T<=55)

Second line N the number of spots in the battle. (2<=N<=50)

Next N*N matrix indicates the time to reach other spots. (Each value in the matrix <=50)

K the number of Divyastras Arjuna had initially. (0<=K<=50)

Output

A Single value indicating the minimum time required to reach Jayadratha.

Example

Input:
1
3
0 9 4
9 0 4
4 4 0
1

Output:
4.5

Explanation

According to given data, you need:

  • 9 units of time to move between spots 0 and 1.
  • 4 units of time to move between spots 0 and 2.
  • 4 units of time to move between spots 1 and 2.
  • You have a single Divyastra.

The optimal solution is to use a Divyastra and move directly from spot 0 to spot 1. This will take 9/2 = 4.5 units of time.


hide comments
nadstratosfer: 2018-04-27 06:20:56

Based on my experiments, values in the matrix are nonnegative integers. Also, judge appears to accept both "x" and "x.0" for integer results.

ferol: 2017-08-23 07:40:01

Can values in the matrix be not integer?
Can they be <=0?


Added by:gohan
Date:2016-01-08
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 MAWK BC NCSHARP COFFEE DART FORTH GOSU JS-MONKEY JULIA KTLN OCT PROLOG PYPY3 R RACKET SQLITE SWIFT UNLAMBDA