#P1948G. MST with Matching

MST with Matching

Description

You are given an undirected connected graph on nn vertices. Each edge of this graph has a weight; the weight of the edge connecting vertices ii and jj is wi,jw_{i,j} (or wi,j=0w_{i,j} = 0 if there is no edge between ii and jj). All weights are positive integers.

You are also given a positive integer cc.

You have to build a spanning tree of this graph; i. e. choose exactly (n1)(n-1) edges of this graph in such a way that every vertex can be reached from every other vertex by traversing some of the chosen edges. The cost of the spanning tree is the sum of two values:

  • the sum of weights of all chosen edges;
  • the maximum matching in the spanning tree (i. e. the maximum size of a set of edges such that they all belong to the chosen spanning tree, and no vertex has more than one incident edge in this set), multiplied by the given integer cc.

Find any spanning tree with the minimum cost. Since the graph is connected, there exists at least one spanning tree.

The first line contains two integers nn and cc (2n202 \le n \le 20; 1c1061 \le c \le 10^6).

Then nn lines follow. The ii-th of them contains nn integers wi,1,wi,2,,wi,nw_{i,1}, w_{i,2}, \dots, w_{i,n} (0wi,j1060 \le w_{i,j} \le 10^6), where wi,jw_{i,j} denotes the weight of the edge between ii and jj (or wi,j=0w_{i,j} = 0 if there is no such edge).

Additional constraints on the input:

  • for every i[1,n]i \in [1, n], wi,i=0w_{i,i} = 0;
  • for every pair of integers (i,j)(i, j) such that i[1,n]i \in [1, n] and j[1,n]j \in [1, n], wi,j=wj,iw_{i,j} = w_{j,i};
  • the given graph is connected.

Print one integer — the minimum cost of a spanning tree of the given graph.

Input

The first line contains two integers nn and cc (2n202 \le n \le 20; 1c1061 \le c \le 10^6).

Then nn lines follow. The ii-th of them contains nn integers wi,1,wi,2,,wi,nw_{i,1}, w_{i,2}, \dots, w_{i,n} (0wi,j1060 \le w_{i,j} \le 10^6), where wi,jw_{i,j} denotes the weight of the edge between ii and jj (or wi,j=0w_{i,j} = 0 if there is no such edge).

Additional constraints on the input:

  • for every i[1,n]i \in [1, n], wi,i=0w_{i,i} = 0;
  • for every pair of integers (i,j)(i, j) such that i[1,n]i \in [1, n] and j[1,n]j \in [1, n], wi,j=wj,iw_{i,j} = w_{j,i};
  • the given graph is connected.

Output

Print one integer — the minimum cost of a spanning tree of the given graph.

Sample Input 1

4 10
0 1 8 0
1 0 1 0
8 1 0 2
0 0 2 0

Sample Output 1

21

Sample Input 2

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

Sample Output 2

14

Note

In the first example, the minimum cost spanning tree consists of edges (1,3)(1, 3), (2,3)(2, 3) and (3,4)(3, 4). The maximum matching for it is 11.

In the second example, the minimum cost spanning tree consists of edges (1,2)(1, 2), (2,3)(2, 3) and (3,4)(3, 4). The maximum matching for it is 22.