CF1556H.DIY Tree
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
William really likes puzzle kits. For one of his birthdays, his friends gifted him a complete undirected edge-weighted graph consisting of n vertices.
He wants to build a spanning tree of this graph, such that for the first k vertices the following condition is satisfied: the degree of a vertex with index i does not exceed di . Vertices from k+1 to n 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 all n vertices 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.
输入格式
The first line of input contains two integers n , k ( 2≤n≤50 , 1≤k≤min(n−1,5) ).
The second line contains k integers d1,d2,…,dk ( 1≤di≤n ).
The i -th of the next n−1 lines contains n−i integers wi,i+1,wi,i+2,…,wi,n ( 1≤wi,j≤100 ): weights of edges (i,i+1),(i,i+2),…,(i,n) .
输出格式
Print one integer: the minimum weight of a spanning tree under given degree constraints for the first k vertices.
输入输出样例
输入#1
10 5 5 3 4 2 1 29 49 33 12 55 15 32 62 37 61 26 15 58 15 22 8 58 37 16 9 39 20 14 58 10 15 40 3 19 55 53 13 37 44 52 23 59 58 4 69 80 29 89 28 48
输出#1
95