D. Minimum Diameter Tree Round #528 (Div. 2)【树】
一、题面
二、分析
该题注意读题的时候有强调边的权值为非负(即可以为0),此题就是求树两个叶子节点之间的最短距离。为了使两个叶子节点之间的距离最短,那么其实就是让每个最后到叶子的那条路径尽量去平摊更多的权值,因为只有这样才能保证最长的哪个路径值是最小的。相当于除了到叶子的路径,其他路径权值都是0。为什么?因为假设其他路径有权值,那么经过这条路径的两个叶子之间的最大距离肯定不是所有情况中最小的。它除了要加到叶子的路径权重还要加该路径权重。
如果你认为可以给这两个到叶子的路径给尽量小的权重,那么相当于打破了平衡,肯定会有更大的最大权重和路径。
三、AC代码
#include <bits/stdc++.h> using namespace std;
const int MAXN = 1e5+;
int Data[MAXN]; int main()
{
int N, W;
while(scanf("%d %d", &N, &W)!=EOF)
{
int x, y, cnt = ;
double ans;
memset(Data, , sizeof(Data));
for(int i = ; i < N; i++)
{
scanf("%d %d", &x, &y);
Data[x]++;
Data[y]++;
}
for(int i = ; i <= N; i++)
{
if(Data[i] == )
cnt++;
}
ans = W*1.0/cnt*2.0;
printf("%.12f\n", ans);
}
return ;
}
D. Minimum Diameter Tree Round #528 (Div. 2)【树】的更多相关文章
- D. Minimum Diameter Tree 思维+猜结论
D. Minimum Diameter Tree 思维+猜结论 题意 给出一颗树 和一个值v 把该值任意分配到任意边上 使得\(\sum\limits_{i,j}p_{ij}=v\) 使得 这颗树任意 ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Educational Codeforces Round 3 E. Minimum spanning tree for each edge LCA/(树链剖分+数据结构) + MST
E. Minimum spanning tree for each edge Connected undirected weighted graph without self-loops and ...
- Educational Codeforces Round 3 E. Minimum spanning tree for each edge 最小生成树+树链剖分+线段树
E. Minimum spanning tree for each edge time limit per test 2 seconds memory limit per test 256 megab ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #528 Div. 1 自闭记
整天自闭. A:有各种讨论方式.我按横坐标排了下然后讨论了下纵坐标单调和不单调两种情况.写了15min也就算了,谁能告诉我printf和cout输出不一样是咋回事啊?又调了10min啊?upd:突然想 ...
- Educational Codeforces Round 3 E. Minimum spanning tree for each edge (最小生成树+树链剖分)
题目链接:http://codeforces.com/contest/609/problem/E 给你n个点,m条边. 问枚举每条边,问你加这条边的前提下组成生成树的权值最小的树的权值和是多少. 先求 ...
- [CF1087D]Minimum Diameter Tree
link 题目大意 有$n$个点的前边权为$0$的树,你要加入$S$边权总量,可以为分数,使得当前树的直径最小. 题目分析 题目过于毒瘤,导致于最后$1$个小时一直在做此题,没想到真的只是一个结论一样 ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
随机推荐
- 733. Flood Fill 简单型染色问题
[抄题]: An image is represented by a 2-D array of integers, each integer representing the pixel value ...
- 734. Sentence Similarity 有字典数组的相似句子
[抄题]: Given two sentences words1, words2 (each represented as an array of strings), and a list of si ...
- PCL点云库中的坐标系(CoordinateSystem)
博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...
- 1.ef 映射关系
1.edmx <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="3 ...
- XMLHttpRequest实现Ajax异步请求
一.XMLHttpRequest的方法 方法 描述 abort() ...
- docker搭建gitbook服务
Gitbook Gitbook简介 GitBook 是一个基于 Node.js 的命令行工具,可使用 Github/Git 和 Markdown 来制作精美的电子书,GitBook 并非关于 Git ...
- What is the AppData folder?
Applies to Windows 8.1, Windows RT 8.1 The AppData folder contains app settings, files, and data spe ...
- 第07章-Spring MVC 的高级技术
Spring MVC 的高级技术 1. Spring MVC配置的替代方案 1.1 自定义DispatcherServlet配置 AbstractAnnotationConfigDispatcherS ...
- adb命令安装及卸载应用
一.手机连接电脑,检测手机是否已开启授权并连接成功 adb devices 二.安装应用 adb install UYUN-CARRIER-Android.apk 三.卸载应用 1.查看应用包名 ad ...
- mysql 游标CURSOR
FETCH cursor_works INTO num,provinceIDs,cityIDs,SourceID; 定义的变量值必须与 游标中的字段不同,一一对应 DECLARE cursor_wor ...