2348: 片区划分

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

A 市有 lns="http://www.w3.org/1998/Math/MathML"> 个村庄(村庄编号为 lns="http://www.w3.org/1998/Math/MathML">1  ),现准备将 lns="http://www.w3.org/1998/Math/MathML"> 个村庄划分为 lns="http://www.w3.org/1998/Math/MathML"> 个区(一个区中要有至少 lns="http://www.w3.org/1998/Math/MathML">1 个村庄),同一个区中的村庄要求有道路可以互相到达(不一定要直达,比如:A 村要去 C 村,可以先先去 B 村,再去 C 村)。

为了节约成本,在划分之前,相关规划部门调研了村庄之间修路的成本,本次调研,共调研到了 lns="http://www.w3.org/1998/Math/MathML"> 条道路的建设成本。

假设所有村庄之间目前没有任何道路,如果要将 lns="http://www.w3.org/1998/Math/MathML"> 个村庄划分为 lns="http://www.w3.org/1998/Math/MathML"> 个区,请求出最少的修路成本?

输入

第一行有三个数lns="http://www.w3.org/1998/Math/MathML">,,(lns="http://www.w3.org/1998/Math/MathML">11000,110000,110)

接下来m行每行三个数 lns="http://www.w3.org/1998/Math/MathML">,,,表示编号为 lns="http://www.w3.org/1998/Math/MathML"> 村到编号为 lns="http://www.w3.org/1998/Math/MathML"> 村修路的费用。(lns="http://www.w3.org/1998/Math/MathML">1,,0<10000)

测试数据保证 lns="http://www.w3.org/1998/Math/MathML"> 村到 lns="http://www.w3.org/1998/Math/MathML"> 村的道路只有 lns="http://www.w3.org/1998/Math/MathML">1 条。

输出

输出一个整数,代表最少的修路成本。

如果按照当前的调研数据,无法将 lns="http://www.w3.org/1998/Math/MathML">个村庄划分为 lns="http://www.w3.org/1998/Math/MathML"> 个区,请输出No Answer。(比如,假设有 lns="http://www.w3.org/1998/Math/MathML">5 个村庄,只有 lns="http://www.w3.org/1998/Math/MathML">2 条道路的建设数据,是无法将 lns="http://www.w3.org/1998/Math/MathML">5 个村庄划分为 lns="http://www.w3.org/1998/Math/MathML">2 个区或者 lns="http://www.w3.org/1998/Math/MathML">1 个区的)。

样例输入 复制

3 1 2
1 2 1

样例输出 复制

1

提示

样例解释

lns="http://www.w3.org/1998/Math/MathML">1 号村到 lns="http://www.w3.org/1998/Math/MathML">2 号村修路成本为 lns="http://www.w3.org/1998/Math/MathML">1 。

样例要求将 lns="http://www.w3.org/1998/Math/MathML">3 个村划分为 lns="http://www.w3.org/1998/Math/MathML">2 个区,只需要修 lns="http://www.w3.org/1998/Math/MathML">1 条路就可以将 lns="http://www.w3.org/1998/Math/MathML">2 个村合并为 lns="http://www.w3.org/1998/Math/MathML">1 个区,加上剩余的 lns="http://www.w3.org/1998/Math/MathML">1 个村,形成了 lns="http://www.w3.org/1998/Math/MathML">2 个区。

因此,样例中只需要在 lns="http://www.w3.org/1998/Math/MathML">1 号村和 lns="http://www.w3.org/1998/Math/MathML">2 号村之间修路,就可以实现划分 lns="http://www.w3.org/1998/Math/MathML">2 个区的目标。

来源