CF BUDDY
← Problems·

1310D · Tourism

2300 · dp, graphs, probabilities

Problem: Masha lives in a country with nn cities numbered from 11 to nn. She lives in the city number 11.

There is a direct train route between each pair of distinct cities ii and jj, where iji \neq j. In total there are n(n1)n(n-1) distinct routes. Every route has a cost, cost for route from ii to jj may be different from the cost of route from jj to ii.

Masha wants to start her journey in city 11, take exactly kk routes from one city to another and as a result return to the city 11. Masha is really careful with money, so she wants the journey to be as cheap as possible. To do so Masha doesn't mind visiting a city multiple times or even taking the same route multiple times.

Masha doesn't want her journey to have odd cycles. Formally, if you can select visited by Masha city vv, take odd number of routes used by Masha in her journey and return to the city vv, such journey is considered unsuccessful.

Help Masha to find the cheapest (with minimal total cost of all taken routes) successful journey.

Input Format: First line of input had two integer numbers n,kn,k (2n80;2k102 \leq n \leq 80; 2 \leq k \leq 10): number of cities in the country and number of routes in Masha's journey. It is guaranteed that kk is even.

Next nn lines hold route descriptions: jj-th number in ii-th line represents the cost of route from ii to jj if iji \neq j, and is 0 otherwise (there are no routes iii \to i). All route costs are integers from 00 to 10810^8.

Output Format: Output a single integer — total cost of the cheapest Masha's successful journey.

Sample Cases

Case 1

Input

5 8
0 1 2 2 0
0 0 1 1 2
0 1 0 0 0
2 1 1 0 0
2 0 1 2 0

Output

2

Case 2

Input

3 2
0 1 1
2 0 1
2 2 0

Output

3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback