HDU3938 Portal(最小生成树 + 计数)

一道关于图论的问题,求解在给定图中,有多少条起点到终点的路径,其路径中最长边的长度小于给定值L。通过构建最小生成树,分析路径最长边的最小值一定在最小生成树上,按边和询问排序,通过枚举最小生成树边来解决此问题。
摘要由CSDN通过智能技术生成

Problem Description

ZLGG found a magic theory that the bigger banana the bigger banana peel .This important theory can help him make a portal in our universal. Unfortunately, making a pair of portals will cost min{T} energies. T in a path between point V and point U is the length of the longest edge in the path. There may be lots of paths between two points. Now ZLGG owned L energies and he want to know how many kind of path he could make.

Input

There are multiple test cases. The first line of input contains three integer N, M and Q (1 < N ≤ 10,000, 0 < M ≤ 50,000, 0 < Q ≤ 10,000). N is the number of points, M is the number of edges and Q is the number of queries. Each of the next M lines contains three integers a, b, and c (1 ≤ a, b ≤ N, 0 ≤ c ≤ 10^8) describing an edge connecting the point a and b with cost c. Each of the following Q lines contain a single integer L (0 ≤ L ≤ 10^8).

Output

Output the answer to each query on a separate line.

Sample Input

10 10 10
7 2 1
6 8 3
4 5 8
5 8 2
2 8 9
6 4 5
2 1 5
8 10 5
7 3 7
7 8 8
10
6
1
5
9
1
8
2
7
6

Sample Output

36
13
1
13
36
1
36
2
16
13

中文题意

给你一个图,有q个询问,每次询问给一个值L,每次询问问的是有多少个点对,这些点对满足起点到终点所有路径中每条路径最长边中取最小值T(有点拗口哈,就是起点到终点所有路径的最长边取min)小于L。

分析

这道题和NOIP2013货车运输很相似。其实只要发现,所有路径的最长边的最小值一定在最小生成树上就行了!为什么呢?我们考虑最长边的最小值对应的那条边,它连接的是两个点集对吧,把它割掉,我们来看看这条边有什么特点。不难发现,这条

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值