He wants to build a spanning tree of this graph, such that for the firstvertices the following condition is satisfied: the degree of a vertex with index does not exceed . Vertices from to may have any degree.
William wants you to find the minimum weight of a spanning tree that satisfies all the conditions.
A spanning tree is a subset of edges of a graph that forms a tree on allvertices of the graph. The weight of a spanning tree is defined as the sum of weights of all the edges included in a spanning tree.
Input DIY Tree solution codeforces
The first line of input contains two integers, ( , ).
The second line containsintegers ( ).
The-th of the next lines contains integers ( ): weights of edges .
William really likes puzzle kits. For one of his birthdays, his friends gifted him a complete undirected edge-weighted graph consisting of nn vertices. He wants to build a spanning tree of this graph, such that for the first kk vertices the following condition is satisfied: the degree of a vertex with index ii does not exceed didi. Vertices from k+1k+1 to nn may have any degree.