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

题目要求a、b两点之间所有的路径中的最大边的最小值。

这题可以用并查集做,因为询问次数很多,所以要离线操作。设数组num[i],只记录i所在集合的总顶点数(一开始以为是记录边的,其实是记录顶点的),先对所有的边排序,从小到大,(其实可以看做是依次枚举最大边的最小值,因为如果这条线段的两端点不在一个集合,即两个集合的边不相连,那么这条线段就起到了桥梁的作用,也就是说任意两个集合的点相连都要通过这条边,因为之前两个集合的最大边的最小值都符合条件,那么如果这条线段也符合条件,就可以把两个集合的点都连起来),因为能量大的值一定包括能量小的路径,所以每次初始化的时候p[i].sum=p[i-1].sum;

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int pre[10006],num[10006];
struct edge
{
int from,to,len;
}e[50006];
struct node
{
int id,num,sum;
}q[10006]; bool cmp1(edge a,edge b)
{
int temp;
if(a.len>b.len){
temp=a.from;a.from=b.from;b.from=temp;
temp=a.to;a.to=b.to;b.to=temp;
return a.len<b.len;
}
return a.len<b.len;
}
bool cmp2(node a,node b)
{
int temp;
if(a.num>b.num){
temp=a.id;a.id=b.id;b.id=temp;
return a.num<b.num;
}
return a.num<b.num;
}
bool cmp3(node a,node b)
{
int temp;
if(a.id>b.id){
temp=a.sum;a.sum=b.sum;b.sum=temp;
return a.id<b.id;
}
return a.id<b.id;
}
int find(int x)
{
int r=x,i,j=x;
while(r!=pre[r])r=pre[r];
while(j!=pre[j]){
i=pre[j];
pre[j]=r;
j=i;
}
return r;
} int main()
{
int n,m,i,j,a,b,c,p,t1,t2,ans;
while(scanf("%d%d%d",&n,&m,&p)!=EOF)
{
for(i=0;i<=n;i++){
pre[i]=i;num[i]=1;
}
for(i=1;i<=m;i++){
scanf("%d%d%d",&e[i].from,&e[i].to,&e[i].len);
}
sort(e+1,e+1+m,cmp1);
for(i=1;i<=p;i++){
scanf("%d",&q[i].num);
q[i].id=i;
}
sort(q+1,q+p+1,cmp2);
ans=1;
q[0].sum=0;
for(i=1;i<=p;i++){
q[i].sum=q[i-1].sum;
while(ans<=m && e[ans].len<=q[i].num){
t1=find(e[ans].from);t2=find(e[ans].to);
if(t1==t2){
ans++;continue;
}
pre[t1]=t2;
q[i].sum+=num[t1]*num[t2];
num[t2]+=num[t1];
ans++;
}
} sort(q+1,q+1+p,cmp3);
for(i=1;i<=p;i++){
printf("%d\n",q[i].sum);
}
}
return 0;
}

hdu3938 Portal的更多相关文章

  1. hdu3938 Portal 离线+并查集

    #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int ...

  2. hdu3938 Portal 离线的并查集

    离线算法是将全部输入都读入,计算出所有的答案以后再输出的方法.主要是为避免重复计算.类似于计算斐波那契数列的时候用打表的方法. 题目:给一个无向图,求有多少个点对,使得两点间的路径上的花费小于L,这里 ...

  3. Windows Azure Storage (18) 使用HTML5 Portal的Azure CDN服务

    <Windows Azure Platform 系列文章目录> Update:2015-04-15 如果读者使用的是国内由世纪互联运维的Azure China服务,请参考笔者的文档:Azu ...

  4. 安装Portal for ArcGIS时如何正确配置HTTPS证书

    SSL协议位于TCP/IP协议与各种应用层协议之间,为数据通讯提供安全支持.SSL协议可分为两层: SSL记录协议(SSL Record Protocol):它建立在可靠的传输协议(如TCP)之上,为 ...

  5. AEAI Portal V3.5.4升级说明,门户集成平台

    1 总体说明 本次升级是AEAI Portal的一次重要升级,主要扩展了开发社区(论坛).移动门户功能,同时修正一些功能BUG等,具体内容如下: 2 升级内容 功能扩展: 扩展开发社区导航 扩展移动门 ...

  6. 手动删除portal中托管服务。

    在portal中将server作为托管联合服务器,然后发布了托管服务.若中间取消了托管联合服务器,再重新连接,那么会出现之前的托管服务无法删除的现象. 下文为怎样手动删除这些服务的方法,(不过貌似之后 ...

  7. server与Portal联合,portal许可过期无法登录。

    server与Portal联合,portal许可过期无法登录,怎样解除联合. 解决方案由峥姐友情提供~~ (1)删除有两种方式(①/②选其一即可): ①类似 链接ttps://sunl.esrichi ...

  8. UNDER THE HOOD OF THE NEW AZURE PORTAL

    http://jbeckwith.com/2014/09/20/how-the-azure-portal-works/ So - I haven’t been doing much blogging ...

  9. Camstar Portal modeling user guid --设置本地时间

    登陆--studio --portal settings -- timezone settings 里面有EST 和EDT两个时间. 现在要设置为北京时间(08:00) 原文: Localizatio ...

随机推荐

  1. 【MyBatis】MyBatis 注解开发

    MyBatis 注解开发 文章源码 环境搭建 Mybatis 也可以使用注解开发方式,这样就可以减少编写 Mapper 映射文件. 常用注解说明: @Insert 实现新增 @Update 实现更新 ...

  2. Java JVM——9.方法区

    前言 方法区是运行时数据区的最后一个部分: 从线程共享与否的角度来看: 大家可能在这里有些疑惑,方法区和元空间的关系到底是怎样的?请往下看,下面会为大家解惑. 栈.堆.方法区的交互关系 下面就涉及了对 ...

  3. Neo4j 图数据库查询

    Cypher 介绍 Cypher 介绍:作为Neo4j的查询语言,"Cypher"是一个描述性的图形查询语言,允许不必编写图形结构的遍历代码对图形存储有表现力和效率的查询.Cyph ...

  4. 【Oracle】dump函数用法

    Oracle dump函数的用法 一.函数标准格式: DUMP(expr[,return_fmt[,start_position][,length]]) 基本参数时4个,最少可以填的参数是0个.当完全 ...

  5. Puzzle (II) UVA - 519

    题目链接: https://vjudge.net/problem/UVA-519 思路: 剪枝+回溯 这个题巧妙的是他按照表格的位置开始搜索,也就是说表格是定的,他不断用已有的图片从(0,0)开始拼到 ...

  6. ctfhub技能树—文件上传—00截断

    什么是00截断 相关教程:http://www.admintony.com/%E5%85%B3%E4%BA%8E%E4%B8%8A%E4%BC%A0%E4%B8%AD%E7%9A%8400%E6%88 ...

  7. 【小菜学网络】交换机与MAC地址学习

    上一小节介绍了 集线器 ,一种工作于物理层的简单网络设备.由于集线器采用广播的方式中继.转发物理信号,传输效率受到极大制约. 精准转发 为了解决集线器工作效率低下的尴尬,我们需要设计一种更高级的网络设 ...

  8. bean与map之间的转化

    import java.util.HashMap; import java.util.Map; import org.apache.commons.beanutils.BeanUtils; impor ...

  9. C#从入门到放弃治疗一:初探C#世界

    C#是一款高级的面向对象语言,运行于.NET framework之上的高级程序设计语言.其语言规范和,语法和java有着惊人的类似之处.所以如果你在学习C#之前有着java的基础,你将快速地入门.当然 ...

  10. TCP服务器程序

    Linux下编写TCP服务器调用的函数顺序为:socket -> bind -> listen -> accept -> recv/send socket 参见:http:// ...