Codeforces Round #250 (Div. 2)D
给你一张无向图,每个点有一个权值,对于一条从l到r 的边权值是l到r路径上最小的点的权值,(多条路取最大的权值),然后求每两个点之间的权值和/点对数
题解:并查集维护,先从点大的边排序,然后依次加边,这样每次加进来的保证是当前最大 的,然后每次合并都要加上两端的最小值*两端的size,类似与每一个最小值算贡献
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; ll a[N],father[N],sz[N];
struct edge{
ll from,to,c;
}e[N];
bool cmp(edge x,edge y)
{
return x.c > y.c;
}
ll Find(ll x)
{
return x==father[x]?x:father[x]=Find(father[x]);
}
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
for(ll i=;i<=n;i++)
{
scanf("%lld",&a[i]);
father[i]=i;
sz[i]=;
}
for(int i=;i<m;i++)
{
scanf("%lld%lld",&e[i].from,&e[i].to);
e[i].c = min(a[e[i].from], a[e[i].to]);
}
sort(e,e+m,cmp);
ll ans=;
for(int i=;i<m;i++)
{
ll x=e[i].from,y=e[i].to;
// cout<<x<<" "<<y<<" "<<sz[x]<<" "<<sz[y]<<endl;
ll fx=Find(x),fy=Find(y);
if(fx!=fy)
{
ans+=min(a[x],a[y])*sz[fx]*sz[fy];
father[fx]=fy;
sz[fy]+=sz[fx];
}
}
ll te=(n-)*n/;
printf("%.12f\n",(double)ans/te);
return ;
}
/******************** ********************/
Codeforces Round #250 (Div. 2)D的更多相关文章
- Codeforces Round #250 (Div. 2)A(英语学习)
链接:http://codeforces.com/contest/437/problem/A A. The Child and Homework time limit per test 1 secon ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集
B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 1) A. The Child and Toy 水题
A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...
- Codeforces Round #250 (Div. 2) A. The Child and Homework
注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C. #include <iost ...
- Codeforces Round #250 (Div. 2) C、The Child and Toy
注意此题,每一个部分都有一个能量值v[i],他移除第i部分所需的能量是v[f[1]]+v[f[2]]+...+v[f[k]],其中f[1],f[2],...,f[k]是与i直接相连(且还未被移除)的部 ...
- Codeforces Round #250 (Div. 2)
感觉不会再爱了,呜呜! A题原来HACK这么多!很多人跟我一样掉坑了! If there is some choice whose description at least twice shorter ...
- Codeforces Round #250 (Div. 2)——The Child and Set
题目链接 题意: 给定goal和limit,求1-limit中的若干个数,每一个数最多出现一次,且这些数的lowbit()值之和等于goal,假设存在这种一些数,输出个数和每一个数:否则-1 分析: ...
- Codeforces Round #250 (Div. 2)—A. The Child and Homework
好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人 被HACK 1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...
随机推荐
- django一些配置与ORM
- leetcode -day 15 Distinct Subsequences
1. Distinct Subsequences Given a string S and a string T, count the number of distinct subsequen ...
- Nodejs关闭windows服务进程
1.根据端口号,查询进程信息命令: netstat -aon | findstr "端口号" 2.根据pid杀死进程命令: taskkill /F /pid 进程号 完整代码: c ...
- Linux学习笔记—vim程序编辑器
vi和vim vim是vi的升级版,支持vi的所有指令 vi的使用 vi分为三种模式:一般模式.编辑模式.命令行模式 一般模式 以vi打开一个文件就直接进入一般模式了,这个模式下可以使用上下左右按键来 ...
- oradebug工具使用(转载)
在之前的HangAnalyze 中有使用oradebug命令,在这篇文章里,我们主要是重点看一下这个oradebug命令: Oracle HANGANALYZE 功能诊断 DB hanging htt ...
- 快速搭建vue脚手架
https://segmentfault.com/a/1190000011275993
- delphi编程创建桌面快捷方式
delphi编程创建桌面快捷方式 uses ActiveX,ComObj,StdCtrls,ShlObj,FileCtrl; procedure TForm1.N2Click(Sender: TO ...
- Cannot format given Object as a Date
这个小错挺有意思的,记录一下 导出Excel的时候,同事直接用 format …… 前提:数据库中该字段是 Timestamp ---- 2016-06-20 22:49:02.967 写个测试说明一 ...
- HDU - 4407 Sum (容斥)
题意:初始序列[1..N](1<=N<=4e5),支持两种操作:1.求区间[x,y]内与p互素的数之和: 2.将x位置的数变为c. 分析:很容易把人骗到线段树的思维中,而实际上操作2单点的 ...
- 对 Java Integer.valueOf() 的一些了解
从一道选择题开始 分析 选项A 选项A中比较的是i01和i02,Integer i01=59这里涉及到自动装箱过程,59是整型常量,经包装使其产生一个引用并存在栈中指向这个整型常量所占的内存,这时 ...