hdu3938 Portal
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.
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).
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
13
1
13
36
1
36
2
16
题目要求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的更多相关文章
- hdu3938 Portal 离线+并查集
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int ...
- hdu3938 Portal 离线的并查集
离线算法是将全部输入都读入,计算出所有的答案以后再输出的方法.主要是为避免重复计算.类似于计算斐波那契数列的时候用打表的方法. 题目:给一个无向图,求有多少个点对,使得两点间的路径上的花费小于L,这里 ...
- Windows Azure Storage (18) 使用HTML5 Portal的Azure CDN服务
<Windows Azure Platform 系列文章目录> Update:2015-04-15 如果读者使用的是国内由世纪互联运维的Azure China服务,请参考笔者的文档:Azu ...
- 安装Portal for ArcGIS时如何正确配置HTTPS证书
SSL协议位于TCP/IP协议与各种应用层协议之间,为数据通讯提供安全支持.SSL协议可分为两层: SSL记录协议(SSL Record Protocol):它建立在可靠的传输协议(如TCP)之上,为 ...
- AEAI Portal V3.5.4升级说明,门户集成平台
1 总体说明 本次升级是AEAI Portal的一次重要升级,主要扩展了开发社区(论坛).移动门户功能,同时修正一些功能BUG等,具体内容如下: 2 升级内容 功能扩展: 扩展开发社区导航 扩展移动门 ...
- 手动删除portal中托管服务。
在portal中将server作为托管联合服务器,然后发布了托管服务.若中间取消了托管联合服务器,再重新连接,那么会出现之前的托管服务无法删除的现象. 下文为怎样手动删除这些服务的方法,(不过貌似之后 ...
- server与Portal联合,portal许可过期无法登录。
server与Portal联合,portal许可过期无法登录,怎样解除联合. 解决方案由峥姐友情提供~~ (1)删除有两种方式(①/②选其一即可): ①类似 链接ttps://sunl.esrichi ...
- 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 ...
- Camstar Portal modeling user guid --设置本地时间
登陆--studio --portal settings -- timezone settings 里面有EST 和EDT两个时间. 现在要设置为北京时间(08:00) 原文: Localizatio ...
随机推荐
- leetcode 1240. 铺瓷砖(回溯,DFS)
题目链接 https://leetcode-cn.com/problems/tiling-a-rectangle-with-the-fewest-squares/ 题意: 用尽可能少的正方形瓷砖来铺地 ...
- 误删除SAP ECC中的profile文件
环境:ECC6.0 EHP4 FOR ORACLE ON WINDWS X64下 今天在RZ10配置系统参数文件的时候,不小心错删除了instance profile文件,这下惨了,这是操作系统层级 ...
- Spring学习03
6.Bean的自动装配 6.1 自动装配说明 自动装配是使用spring满足bean依赖的一种方法 spring会在应用上下文中为某个bean寻找其依赖的bean. Spring中bean的三种装配机 ...
- ROS教程(一):ROS安装教程(详细图文)
ros教程:ros安装 目录 前言 一.版本选择 二.开始安装 2.1 软件中心配置 2.2 添加源 2.3 安装 三.验证ROS 前言 关于ROS(Robot OS 机器人操作系统),估计看这个教程 ...
- mysql(连接查询和数据库设计)
--创建学生表 create table students ( id int unsigned not null auto_increment primary key, name varchar(20 ...
- Bitter.Core系列五:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之 示例 分页聚联查询
Bitter.Core 在聚联/分页聚联查询的时候,采用原生的MSSQL, MYSQL 语句查询,做过复杂高级项目的人知道,原生的聚合查询代码执行效率更高,更快,更容易书写,开发量最少. 借助原生的M ...
- Go RPC 框架 KiteX 性能优化实践 原创 基础架构团队 字节跳动技术团队 2021-01-18
Go RPC 框架 KiteX 性能优化实践 原创 基础架构团队 字节跳动技术团队 2021-01-18
- Object level permissions support
django-guardian (1.1.1+) - Object level permissions support. Home - Django REST framework https://ww ...
- 【题解】CF952F 2 + 2 != 4
题目传送门 首先这道题没有翻译,这是很奇怪的,经过了(bai)查(du)字(fan)典(yi)之后,你会发现,什么用都没有-- 楼下的 dalao 们给的解释非常的模糊(果然还是我太弱了),于是我自己 ...
- OIer 生涯绊脚石
字符串 哈希进制搞质数 \({\color{OrangeRed}{KMP}}\) 数组别开太大,否则 \({\color{Gold}{TLE}}\) 没有必要 \({\color{Cyan}{strl ...