cf 500 D. New Year Santa Network
直接按边分,2个点在边的一边,1个在另一边,组合出来就是这个边对答案的贡献,权值换了就再重新算个数而已。
#include <bits/stdc++.h>
#define LL long long
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
LL n,m,cnt=;
double ans,tot;
struct edge{
int from,to,next;
LL v,T;
}e[];
LL size[],head[],deep[];
void insert(int x, int y, int v)
{
e[++cnt].next=head[x]; e[cnt].from=x; e[cnt].to=y; e[cnt].v=v; head[x]=cnt;
}
void dfs(int x, int fa)
{
size[x]=;
for (int i=head[x];i;i=e[i].next)
{
if (e[i].to==fa) continue;
deep[e[i].to]=deep[x]+;
dfs(e[i].to,x);
size[x]+=size[e[i].to];
}
}
int main(int argc, char const *argv[])
{
n=ra(); tot=n*(n-)*(n-)/6.0;
for (int i=; i<n; i++)
{
int x=ra(),y=ra(),v=ra();
insert(x,y,v); insert(y,x,v);
}
dfs(,);
for (int i=; i<=cnt; i+=)
{
int now=i/,x=e[i].from,y=e[i].to;
if (deep[x]>deep[y]) swap(x,y);
LL s1=n-size[y],s2=size[y];
e[i].T+=s1*s2*((LL)n-);
ans+=e[i].T*e[i].v;
}
m=ra();
for (int i=; i<=m; i++)
{
int x=ra(),y=ra();
LL now=x*;
ans-=(e[now].v-y)*e[now].T;
e[now].v=y;
printf("%.10lf\n",(double)ans/tot);
}
return ;
}
cf 500 D. New Year Santa Network的更多相关文章
- D. New Year Santa Network 解析(思維、DFS、組合、樹狀DP)
Codeforce 500 D. New Year Santa Network 解析(思維.DFS.組合.樹狀DP) 今天我們來看看CF500D 題目連結 題目 給你一棵有邊權的樹,求現在隨機取\(3 ...
- Good Bye 2014 D. New Year Santa Network 图论+期望
D. New Year Santa Network New Year is coming in Tree World! In this world, as the name implies, th ...
- cf500D New Year Santa Network
D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces 500D New Year Santa Network(树 + 计数)
D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces 500D. New Year Santa Network
题目大意 给你一颗有\(n\)个点的树\(T\),边上有边权. 规定,\(d(i,j)\)表示点i到点j路径上的边权之和. 给你\(q\)次询问,每次询问格式为\(i, j\),表示将按输入顺序排序的 ...
- CF 500D New Year Santa Network tree 期望 好题
New Year is coming in Tree World! In this world, as the name implies, there are n cities connected b ...
- CF 500 C. New Year Book Reading 贪心 简单题
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...
- 【codeforces 500D】New Year Santa Network
[题目链接]:http://codeforces.com/problemset/problem/500/D [题意] 有n个节点构成一棵树; 让你随机地选取3个不同的点a,b,c; 然后计算dis(a ...
- CF 500 B. New Year Permutation 并查集
User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permut ...
随机推荐
- 图片的onload事件与better-scroll结合[ 当fastclick插件和better-scroll发生冲突导致点击事件失效时,可以给需要点击的元素加一个class="needsclick"]
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Eclipse中创建新的SpringBoot项目(打包并且部署到tomcat)
Spring-boot因为其对jar包的高度集成以及简化服务配置,快速部署等的优点,逐渐成为Java开发人员的热衷的框架.下面演示一下怎么在Eclipse中新建Spring-boot项目以及打包部署. ...
- python生成器三元表达式
使用yield返回 例如: def test(): yield 1 yield 2 yield 3 yield 4 v = test() print(v.__next__()) print(v.__ ...
- 「Luogu P2253 好一个一中腰鼓!」
就这道题的理论难度来说绿题是有点低了,但是这道题的实际难度来看,顶多黄题,所以建议加强数据或出数据升级版. 前置芝士 线段树:具体可以看我的另一篇文章. 具体做法 暴力的方法想必都会,所以来讲一下正解 ...
- The Proof of Fibonacci GCD
\[\Large \text{The Proof of Fibonacci GCD}\] \[\text{By Sangber}\] \(\text{Fibonacci Sequence}\) \(\ ...
- JAVA 集合 List 分组的两种方法
CSDN日报20170219--<程序员的沟通之痛> [技术直播]揭开人工智能神秘的面纱 程序员1月书讯 云端应用征文大赛,秀绝招,赢无人机! JAVA 集合 List 分组的两种方法 2 ...
- jmeter之http请求用csv读取中文乱码
jmeter3.2版本中CSV Data Set Config从本地读取静态文件的时候,遇到中文乱码的解决方式如下: CSV Data Set Config设置 http请求数据显示乱码 把txt文档 ...
- 5G/NR 帧结构
原文链接:http://www.sharetechnote.com/html/5G/5G_FrameStructure.html 在学术界和3GPP中对帧结构进行了长时间的讨论,现在我们就NR(5G) ...
- iOS Framework制作流程
1.新建工程选择iOS —> Cocoa Touch Framework 2.进入创建好的工程删除掉自带的工程同名头文件 3.添加所需文件 4.TARGETS —> Build Setti ...
- stm32CubeMx CAN 发送数据
平台 STM32F429 软件 STM32CubeMx 5.0.0 固件库 STM32Cube_FW_F4_V1.23.0 目的: 实现 CAN 的发送 一 简介 CAN是控制器局域网络(Co ...