题目链接

没有发现那个点,无奈。

 #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(并查集)的更多相关文章

  1. hdu 4750 Count The Pairs(并查集+二分)

    Problem Description With the 60th anniversary celebration of Nanjing University of Science and Techn ...

  2. hdu 4750 Count The Pairs(并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 代码: #include<cstdio> #include<cstring&g ...

  3. HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)

    Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  4. HDU 4750 Count The Pairs ★(图+并查集+树状数组)

    题意 给定一个无向图(N<=10000, E<=500000),定义f[s,t]表示从s到t经过的每条路径中最长的边的最小值.Q个询问,每个询问一个t,问有多少对(s, t)使得f[s, ...

  5. 2013南京网赛1003 hdu 4750 Count The Pairs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4750 题意:给出一个无向图,f(a,b)表示从点a到点b的所有路径中的每条路径的最长边中的最小值,给出 ...

  6. HDU 4750 Count The Pairs (离线并查集)

    按边从小到大排序. 对于每条边(from, to, dist),如果from和to在同一个集合中,那么这条边无意义,因为之前肯定有比它更小的边连接了from和to. 如果from和to不属于同一个集合 ...

  7. [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 ...

  8. hdu 4750 Count The Pairs (2013南京网络赛)

    n个点m条无向边的图,对于q个询问,每次查询点对间最小瓶颈路 >=f 的点对有多少. 最小瓶颈路显然在kruskal求得的MST上.而输入保证所有边权唯一,也就是说f[i][j]肯定唯一了. 拿 ...

  9. hdu 3635 Dragon Balls(并查集应用)

    Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...

随机推荐

  1. 在asp.net利用jquery.MultiFile实现多文件上传(转载)

    转载地址:http://www.cnblogs.com/scy251147/archive/2010/09/30/1839313.html 官网链接:http://www.fyneworks.com/ ...

  2. 【翻译十七】java-并发之高性能对象

    High Level Concurrency Objects So far, this lesson has focused on the low-level APIs that have been ...

  3. HDU3434 Sequence Adjustment

    题意:给你含有n个数的序列,每次你可以选一个子序列将上面所有的数字加1或者减1,目标是把所有数字变成相同的,问最少步数,和那个相同的数字有多少种可能. 将原序列转化为差分序列,即a[2] - a[1] ...

  4. 登录成功,拿到token

    历尽波折,终于成功登录并拿到了token: - (LoginResultDto *)login:(NSString *)userName andPassword:(NSString *)passwor ...

  5. PHP日期操作类代码-农历-阳历转换、闰年、计算天数等

    <?php class Lunar { var $MIN_YEAR = 1891; var $MAX_YEAR = 2100; var $lunarInfo = array( array(0,2 ...

  6. hdu 4278 2012天津赛区网络赛 数学 *

    8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...

  7. 重新开始刷dp,哈哈哈

    转载于: http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2015年1月29日 从头开始

  8. VS2010和matlab2010混合编程中char16_t重定义的问题

    原因是VS2010中的yvals.h添加了char16_t的定义,而Matlab的matrix.h也包含对char16_t的定义,所以同时包含这两个头文件的话,会导致重复定义char16_t的错误.只 ...

  9. JS 获取元素当前的样式信息

    HTMLElement.prototype.__defineGetter__("currentStyle", function () { return this.ownerDocu ...

  10. cocos2dx游戏开发——微信打飞机学习笔记(一)——开发准备

    一.环境的搭建 1.Windows开发准备: (1)软件下载及安装 •下载Cocos2d-x 最新版本:http://www.cocos2d-x.org/download 或者从Cocos2d-x G ...