直接按边分,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的更多相关文章

  1. D. New Year Santa Network 解析(思維、DFS、組合、樹狀DP)

    Codeforce 500 D. New Year Santa Network 解析(思維.DFS.組合.樹狀DP) 今天我們來看看CF500D 題目連結 題目 給你一棵有邊權的樹,求現在隨機取\(3 ...

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

  3. cf500D New Year Santa Network

    D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input st ...

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

  5. Codeforces 500D. New Year Santa Network

    题目大意 给你一颗有\(n\)个点的树\(T\),边上有边权. 规定,\(d(i,j)\)表示点i到点j路径上的边权之和. 给你\(q\)次询问,每次询问格式为\(i, j\),表示将按输入顺序排序的 ...

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

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

  8. 【codeforces 500D】New Year Santa Network

    [题目链接]:http://codeforces.com/problemset/problem/500/D [题意] 有n个节点构成一棵树; 让你随机地选取3个不同的点a,b,c; 然后计算dis(a ...

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

随机推荐

  1. Linux--如何实现虚拟机与主机之间的文件传输无需第三方,即可轻松设置共享文件夹(适合所有人群)

    无需第三方插件,设置共享文件夹 第一步:虚拟机->设置 第二步:选项->共享文件夹->总是启用->添加 第三步:点击下一步 第四步:浏览(选择主机路径)->下一步 第五步 ...

  2. Linux--常用的linux基本命令学习大全01(适合所有人群)

    常用 Linux 命令的基本使用 序号 命令 对应英文 作用 01 ls list 查看当前文件夹下的内容 02 pwd print wrok directory 查看当前所在文件夹 03 cd [目 ...

  3. kubernetes 1.17.2 kubeadm部署 证书修改为100年

    [root@hs-k8s-master01 ~]# cd /data/ [root@hs-k8s-master01 data]# ls docker [root@hs-k8s-master01 dat ...

  4. Go 开发者平均年薪 46 万?爬数据展示国内 Go 的市场行情到底如何

    随着云原生时代的到来,拥有高并发性.语法易学等特点的 Golang 地位逐渐凸显,在云原生编程中占据了主导地位.在近期出炉的 TIOBE 10 月编程语言排行榜中,Golang 从前一个月的 16 位 ...

  5. leetcode菜鸡斗智斗勇系列(5)--- 寻找拥有偶数数位的数字

    1.原题: https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ Given an array nums of ...

  6. Maven项目- Servlet的抽取和优化 java.lang.NoSuchMethodException 的解决方法

    优化servlet,减少servlet的数量,便于开发与维护.现在是一个功能一个Servlet,将其优化为一个模块一个Servlet,BaseServlet的抽取和优化,相当于在数据库中一张表对应一个 ...

  7. RCast 66: 射影几何与Rho演算

    Greg Meredith与Isaac DeFrain和Christian Williams一起讨论了射影几何及其在Rho演算中的作用. 原文链接及音频 https://blog.rchain.coo ...

  8. String类与StringBuffer类

    String类与StringBuffer类   一.String类和StringBuffer类的区别 String类是不可变类,新建的对象为不可变对象(String类的内容和长度是固定的),一旦被创建 ...

  9. IDEA 单行注释与代码对齐

    效果 修改步骤 Settings -> Editor -> Code Style (1)修改.java文件的注释 comment   评论.注释.意见. (2)修改.html文件的注释 ( ...

  10. Lesson 3 Matterhorn man

    What was the main objective of early mountain climbers? Morden alpinists try to climb mountains by a ...