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 ...
随机推荐
- 阿里云服务器ubantu创建新用户登录显示问题
在root用户下输入:vi /etc/passwd,找到添加的用户,在后面加上/bin/bash 重新登录即回复正常
- 配置web应用全局的错误页面
- c++类的创建与使用
c++类的创建与使用 前言: 之前一直对c++的类的创建与使用不太熟悉,有些概念还是有点模糊,借着这次休息的机会整理一下对应是知识点.如有不正确的地方还希望各位读者批评指正. 一.C++中public ...
- QQ企业通---登录模块设计--知识点
Rectangle 成员 存储一组整数,共四个,表示一个矩形的位置和大小.对于更高级的区域函数,请使用 Region 对象. Form与Control的区别? 窗体也是控件,继承Control类.可 ...
- 每日算法 - day 15
每日算法 those times when you get up early and you work hard; those times when you stay up late and you ...
- Linux centosVMware vim 编辑模式、vim命令模式、vim实践
一.编辑模式.命令模式 在一般模式下输入:或/可进入命令模式.在该模式下可进行走索某个字符或字符串,也可保存.替换.退出.显示行号等. /word:在光标之后查找一个字符串word,按n向后继续搜索 ...
- springboot#配置文件处理
1. 加载自定义属性文件 2. 通过bean聚合相关属性 1. 在启动类上通过如下注解可以加载自定义的属性文件 @PropertySource(value = {"classpath:pro ...
- WebAPI实例
@{ ViewBag.Title = "About"; } @*<script src="~/Scripts/jquery-1.7.1.min.js"&g ...
- AOP五种执行时机
动态代理四种增强方式 先创建一个service类 package com.zzj.calculatar.service; import org.springframework.stereotype.S ...
- Vue + Webpack 根据不同环境打包
修改 prod.env.js // 当前正在运行的脚本名称 const TARGET = process.env.npm_lifecycle_event // 第一个参数 let argv = pro ...