题目:https://cn.vjudge.net/contest/296683
A - Abandoned countryHDU - 5723 求最小生成树,再求这个最小生成树上任意两个点的最短距离期望 任意两个点情况数就是C(n,2),任意两个点的距离和可以转化为求每条边的贡献和 而每条边的贡献就是u->v valsz[v](n-sz[v]用dp[u]储存所有和u相连的边的贡献和,简单树形Dp
#include
using namespace std;
#define ll long long
const int maxn=100010;
const int maxm=1000010;
struct edge{
int u,v,w,nxt;
}e[maxm];
int head[maxn],tot;
int n,m;
int f[maxn];
void init()
{
memset(head,-1,sizeof(head));
tot=0;
}
void addedge(int u,int v,int w)
{
e[tot].u=u;
e[tot].v=v;
e[tot].w=w;e[tot].nxt=head[u];
head[u]=tot++;
}
int find1(int x)
{
return x==f[x]?x:f[x]=find1(f[x]);
}
bool union1(int a,int b)
{
int fa=find1(a),fb=find1(b);
if(fa!=fb){
f[fa]=fb;
return false;
}
return true;
}
struct node{
int a,b,c;
}hh[maxm];
bool cmp(const node& a,const node& b)
{
return a.c
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?