CF1556H.DIY Tree

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:256MB

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 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 did_i. Vertices from k+1k + 1 to nn 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 nn 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.

威廉非常喜欢拼图套件。在他某次生日时,朋友们送给他一个由 nn 个顶点构成的无向带权完全图。

他希望在该图中构造一棵生成树,使得对前 kk 个顶点满足如下条件:编号为 ii 的顶点的度数不超过 did_i。而编号从 k+1k + 1 到 nn 的顶点则对度数不作限制。

威廉希望你找出满足所有上述条件的生成树的最小总权重。

生成树是图中边的一个子集,它在图的所有 nn 个顶点上构成一棵树。生成树的权重定义为其中所包含的所有边的权重之和。

输入格式

The first line of input contains two integers nn, kk (2≤n≤502 \leq n \leq 50, 1≤k≤min(n−1,5)1 \leq k \leq min(n - 1, 5)).

The second line contains kk integers d1,d2,…,dkd_1, d_2, \ldots, d_k (1≤di≤n1 \leq d_i \leq n).

The ii-th of the next n−1n - 1 lines contains n−in - i integers wi,i+1,wi,i+2,…,wi,nw_{i,i+1}, w_{i,i+2}, \ldots, w_{i,n} (1≤wi,j≤1001 \leq w_{i,j} \leq 100): weights of edges (i,i+1),(i,i+2),…,(i,n)(i,i+1),(i,i+2),\ldots,(i,n).

输入的第一行包含两个整数 nn 和 kk(2≤n≤502 \leq n \leq 50,1≤k≤min⁡(n−1,5)1 \leq k \leq \min(n - 1, 5))。

第二行包含 kk 个整数 d1,d2,…,dkd_1, d_2, \ldots, d_k(1≤di≤n1 \leq d_i \leq n)。

接下来的 n−1n - 1 行中,第 ii 行包含 n−in - i 个整数 wi,i+1,wi,i+2,…,wi,nw_{i,i+1}, w_{i,i+2}, \ldots, w_{i,n}(1≤wi,j≤1001 \leq w_{i,j} \leq 100),表示边 (i,i+1),(i,i+2),…,(i,n)(i,i+1), (i,i+2), \ldots, (i,n) 的权重。

输出格式

Print one integer: the minimum weight of a spanning tree under given degree constraints for the first kk vertices.

输出一个整数:在给定前 kk 个顶点的度数约束下,生成树的最小权重。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页