当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5624:KK's Reconstruction

题目描述
Our lovely KK has a difficult Social problem.
A big earthquake happened in his area.
$N\left( 2\leq N\leq 2000\right)$ cities have been implicated. All the roads between them are destroyed.
Now KK was commissioned to rebuild these roads.
However, after investigation,KK found that some roads are too damaged to rebuild.
Therefore, there are only $M\left( 0\leq M\leq 15000\right)$ roads can be rebuilt.
KK needs to make sure that there is a way between any two cities, and KK wants to rebuild roads as few as possible.
With rebuilding minimal number of roads, he also wants to minimize the difference between the price of the most expensive road been built and the cheapest one.
输入解释
The first line of the input file contains an integer $T\left( 1\leq T\leq 10\right)$, which indicates the number of test cases.

For each test case,The first line includes two integers $N\left( 2\leq N\leq 2000\right)$,$M\left( 0\leq M\leq 15000\right)$.

The next $M$ lines include three integers $a,b,c(a\neq b,1\leq c\leq 2*{10}^{9})$,indicating there is a undirected edge between $a$ and $b$,the cost is $c$.
输出解释
For each test case, output the smallest difference between the price of the most expensive road and the cheapest one.If there is no legal solution, then output -1.
输入样例
2
5 10
1 2 9384
1 3 887
1 4 2778
1 5 6916
2 3 7794
2 4 8336
2 5 5387
3 4 493
3 5 6650
4 5 1422
2 0
输出样例
1686
-1
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5624

最后修改于 2020-10-25T23:24:18+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 65536/65536K(Java/Others)