HDU 4750 Count The Pairs(并查集)
没有发现那个点,无奈。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
#define LL __int64
int o[],rank[];
struct node
{
int u,v,w;
} edge[];
int n,m;
int que[];
LL ans[];
bool cmp(node a,node b)
{
return a.w < b.w;
}
int find(int x)
{
int r,t;
r = x;
while(x != o[x])
x = o[x];
while(r != x)
{
t = o[r];
o[r] = x;
r = t;
}
return x;
}
void merge(int x,int y)
{
x = find(x);
y = find(y);
if(x != y)
{
o[x] = y;
rank[y] += rank[x];
}
}
int bin(int x)
{
int str,end,mid;
str = ;
end = m-;
if(x > que[end])
return m;
while(str < end)
{
mid = (str+end)/;
if(que[mid] < x)
str = mid + ;
else
end = mid;
}
return str;
}
int main()
{
int i,u,v,t;
LL sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i = ;i < n;i ++)
{
rank[i] = ;
o[i] = i;
}
for(i = ; i < m; i ++)
{
scanf("%d%d%d",&edge[i].u,&edge[i].v,&edge[i].w);
que[i] = edge[i].w;
ans[i] = ;
}
sort(que,que+m);
sort(edge,edge+m,cmp);
sum = ;
for(i = ; i < m; i ++)
{
u = find(edge[i].u);
v = find(edge[i].v);
if(u != v)
{
ans[i] = (LL)rank[u] * rank[v]*;
sum += (LL)rank[u] * rank[v]*;
merge(u,v);
}
}
for(i = ;i < m;i ++)
ans[i] = ans[i] + ans[i-];
scanf("%d",&t);
for(i = ; i < t; i ++)
{
scanf("%d",&u);
v = bin(u);
if(v == )
printf("%I64d\n",sum);
else
printf("%I64d\n",sum-ans[v-]);
}
}
return ;
}
HDU 4750 Count The Pairs(并查集)的更多相关文章
- hdu 4750 Count The Pairs(并查集+二分)
Problem Description With the 60th anniversary celebration of Nanjing University of Science and Techn ...
- hdu 4750 Count The Pairs(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 代码: #include<cstdio> #include<cstring&g ...
- HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- HDU 4750 Count The Pairs ★(图+并查集+树状数组)
题意 给定一个无向图(N<=10000, E<=500000),定义f[s,t]表示从s到t经过的每条路径中最长的边的最小值.Q个询问,每个询问一个t,问有多少对(s, t)使得f[s, ...
- 2013南京网赛1003 hdu 4750 Count The Pairs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意:给出一个无向图,f(a,b)表示从点a到点b的所有路径中的每条路径的最长边中的最小值,给出 ...
- HDU 4750 Count The Pairs (离线并查集)
按边从小到大排序. 对于每条边(from, to, dist),如果from和to在同一个集合中,那么这条边无意义,因为之前肯定有比它更小的边连接了from和to. 如果from和to不属于同一个集合 ...
- [2013 ACM/ICPC Asia Regional Nanjing Online C][hdu 4750]Count The Pairs(kruskal + 二分)
http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意: 定义f(u,v)为u到v每条路径上的最大边的最小值..现在有一些询问..问f(u,v)>=t ...
- hdu 4750 Count The Pairs (2013南京网络赛)
n个点m条无向边的图,对于q个询问,每次查询点对间最小瓶颈路 >=f 的点对有多少. 最小瓶颈路显然在kruskal求得的MST上.而输入保证所有边权唯一,也就是说f[i][j]肯定唯一了. 拿 ...
- hdu 3635 Dragon Balls(并查集应用)
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...
随机推荐
- ASP.NET Web API 控制请求频率
参考地址:http://www.cnblogs.com/shanyou/p/3194802.html 安装nuget包:WebApiContrib 很多的api,例如GitHub’s API 都有流量 ...
- POJ2065 SETI(高斯消元 同模方程)
(a1 * 1^0 + a2 * 1^1 + ... an * 1^n - 1) % P = f1 .... (a1 * n^0 + a2 * n^1 + ... an - 1 * ...
- hdu 2891 中国剩余定理
从6点看到10点,硬是没算出来,早知道玩游戏去了,艹,明天继续看 不爽,起来再看,终于算是弄懂了,以后超过一个小时的题不会再看了,不是题目看不懂,是水平不够 #include<cstdio> ...
- [转]svn常用命令
谢谢原作者:http://blog.sina.com.cn/s/blog_963453200101eiuq.html 1.检出svn co http://路径(目录或文件的全路径) [本地目录全路 ...
- 用PowerShell脚本实现对SharePoint页面Title的修改
存在这样一种情况,对应的page已经部署到product的SharePoint环境中,那么在部署下一个版本的时候就不允许把已经创建好的page删除再创建,因此page中修改过的属性就不能再次部署到Sh ...
- 智能车学习(五)—— dac学习
一.代码共享: 1.dac.h #ifndef DAC_H_ #define DAC_H_ #include "common.h" // 2.2 DAC控制寄存器0 位定义 #de ...
- Linux C编程(2) dgb调试
1. 首先编写一个用于调试的测试程序test.c #include <stdio.h> int get_sum(int n) { ,i; ; i <=n ; i++) { sum+= ...
- 【J2EE入门】13个规范
看过了j2ee教学视频,真的让我痛彻心扉,那叫痛并快乐着,痛是因为看了这么长时间,自己只知道了13个规范的概念:同样,快乐也正是因为我知道了13个规范的概念,接下来就是逐项实践的学习. 看了教学视频, ...
- HashMap合并相同key的value
Map<String, String> map1 = new HashMap<>(); map1.put("x", "y"); map1 ...
- 【Tomcat】直接启动tomcat时为tomcat指定JDK 而不是读取环境变量中的配置
在windows环境下以批处理文件方式启动tomcat,只要运行<CATALINA_HOME>/bin/startup.bat这个文件,就可以启动Tomcat.在启动时,startup.b ...