给你一张无向图,每个点有一个权值,对于一条从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的更多相关文章

  1. Codeforces Round #250 (Div. 2)A(英语学习)

    链接:http://codeforces.com/contest/437/problem/A A. The Child and Homework time limit per test 1 secon ...

  2. 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, ...

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

  4. 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/ ...

  5. 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/ ...

  6. Codeforces Round #250 (Div. 2) A. The Child and Homework

    注意题目长度不能考虑前缀,而且如果即存在一个选项的长度的两倍小于其他所有选项的长度,也存在一个选项的长度大于其他选项长度的两倍,则答案不是一个好的选择,只能选择C. #include <iost ...

  7. 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直接相连(且还未被移除)的部 ...

  8. Codeforces Round #250 (Div. 2)

    感觉不会再爱了,呜呜! A题原来HACK这么多!很多人跟我一样掉坑了! If there is some choice whose description at least twice shorter ...

  9. Codeforces Round #250 (Div. 2)——The Child and Set

    题目链接 题意: 给定goal和limit,求1-limit中的若干个数,每一个数最多出现一次,且这些数的lowbit()值之和等于goal,假设存在这种一些数,输出个数和每一个数:否则-1 分析: ...

  10. Codeforces Round #250 (Div. 2)—A. The Child and Homework

         好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人  被HACK  1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...

随机推荐

  1. XP系统中IIS访问无法显示网页,目前访问网站的用户过多。终极解决办法

    无法显示网页 目前访问网站的用户过多. -------------------------------------------------------------------------------- ...

  2. Java Concurrent happens-before

    happens-before relation on memory operations such as reads and writes of shared variables. The resul ...

  3. sql server dba之路

    转自:https://blog.csdn.net/dba_huangzj/article/details/7841441 在专职DBA工作一年过一个月以后,开通了CSDN的博客专栏,在第一篇文章中,我 ...

  4. 多线程并发练习(Day35)

    练习一 #_*_coding:utf-8_*_ #!/usr/bin/env python import multiprocessing import threading import socket ...

  5. wechat多开

    右键wechat查看属性,找到目标(wechat的执行路径),复制 然后在桌面新建文档,输入下面命令,想多开几个就复制几行 start 复制的目标 另存为bat文件,所有文件类型 双击运行

  6. 微信小程序组件text

    基础内容text:官方文档 Demo Code var initData = 'this is first line\nthis is second line' var extraLine = []; ...

  7. smarty内置函数

      1.{append} 追加 2.{assign} 赋值 3.{block} 块 4.{call} 调用 5.{capture}捕获 6.{config_load}用来从配置文件中加载config变 ...

  8. CodeForces - 919D Substring (拓扑排序+dp)

    题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...

  9. java sql解析

    https://github.com/JSQLParser/JSqlParser 淘宝博客:http://www.searchtb.com/category/%E6%90%9C%E7%B4%A2%E5 ...

  10. jQuery双向滑动杆 设置数值百分比

    在线演示 本地下载