CF1085D.Minimum Diameter Tree

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a tree (an undirected connected graph without cycles) and an integer ss.

Vanya wants to put weights on all edges of the tree so that all weights are non-negative real numbers and their sum is ss. At the same time, he wants to make the diameter of the tree as small as possible.

Let's define the diameter of a weighed tree as the maximum sum of the weights of the edges lying on the path between two some vertices of the tree. In other words, the diameter of a weighed tree is the length of the longest simple path in the tree, where length of a path is equal to the sum of weights over all edges in the path.

Find the minimum possible diameter that Vanya can get.

给你一棵树(即一个无环的无向连通图)和一个整数 ss。

万尼亚希望为树的所有边赋予权重,使得所有权重均为非负实数,且它们的总和为 ss。同时,他希望使该树的直径尽可能小。

我们定义加权树的直径为:树中任意两个顶点之间路径上所有边的权重之和的最大值。换言之,加权树的直径即树中最长简单路径的长度,其中路径的长度等于该路径上所有边的权重之和。

求万尼亚所能得到的最小可能直径。

输入格式

The first line contains two integer numbers nn and ss (2≤n≤1052 \leq n \leq 10^5, 1≤s≤1091 \leq s \leq 10^9) — the number of vertices in the tree and the sum of edge weights.

Each of the following n−1n−1 lines contains two space-separated integer numbers aia_i and bib_i (1≤ai,bi≤n1 \leq a_i, b_i \leq n, ai≠bia_i \neq b_i) — the indexes of vertices connected by an edge. The edges are undirected.

It is guaranteed that the given edges form a tree.

第一行包含两个整数 nn 和 ss(2≤n≤1052 \leq n \leq 10^5,1≤s≤1091 \leq s \leq 10^9)—— 分别表示树中顶点的数量以及所有边权值的总和。

接下来的 n−1n-1 行,每行包含两个以空格分隔的整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,ai≠bia_i \neq b_i)—— 表示由一条边连接的两个顶点的编号。这些边是无向的。

保证所给的边构成一棵树。

输出格式

Print the minimum diameter of the tree that Vanya can get by placing some non-negative real weights on its edges with the sum equal to ss.

Your answer will be considered correct if its absolute or relative error does not exceed 10−610^{-6}.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if ∣a−b∣max(1,b)≤10−6\frac {|a-b|} {max(1, b)} \leq 10^{-6}.

输出Vanya通过在树的边上赋予若干非负实数权重(权重总和为 ss)所能得到的树的最小直径。

若你的答案的绝对误差或相对误差不超过 10−610^{-6},则视为正确。

形式化地,设你的答案为 aa,评测机的答案为 bb。当且仅当 ∣a−b∣max⁡(1,b)≤10−6\frac{|a-b|}{\max(1, b)} \leq 10^{-6} 时,你的答案被视为正确。

输入输出样例

  • 输入#1

    4 3
    1 2
    1 3
    1 4

    输出#1

    2.000000000000000000
  • 输入#2

    6 1
    2 1
    2 3
    2 5
    5 4
    5 6

    输出#2

    0.500000000000000000
  • 输入#3

    5 5
    1 2
    2 3
    3 4
    3 5

    输出#3

    3.333333333333333333

说明/提示

In the first example it is necessary to put weights like this:

It is easy to see that the diameter of this tree is 22. It can be proved that it is the minimum possible diameter.

In the second example it is necessary to put weights like this:

在第一个例子中,需要按如下方式放置权重:

容易看出,该树的直径为 22。可以证明这是可能的最小直径。

在第二个例子中,需要按如下方式放置权重:

输入解题思路,AI测评打分。不知道怎么写?

首页