A14378 | DIY Tree
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $d_i$ . 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.
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 $d_i$ . 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 \leq n \leq 50$ , $1 \leq k \leq min(n - 1, 5)$ ).
The second line contains $k$ integers $d_1, d_2, \ldots, d_k$ ( $1 \leq d_i \leq n$ ).
The $i$ -th of the next $n - 1$ lines contains $n - i$ integers $w_{i,i+1}, w_{i,i+2}, \ldots, w_{i,n}$ ( $1 \leq w_{i,j} \leq 100$ ): weights of edges $(i,i+1),(i,i+2),\ldots,(i,n)$ .
The second line contains $k$ integers $d_1, d_2, \ldots, d_k$ ( $1 \leq d_i \leq n$ ).
The $i$ -th of the next $n - 1$ lines contains $n - i$ integers $w_{i,i+1}, w_{i,i+2}, \ldots, w_{i,n}$ ( $1 \leq w_{i,j} \leq 100$ ): weights of edges $(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 $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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted