当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5664:Lady CA and the graph

题目描述
Lady CA has a tree with $n$ points numbered $1,2,...,n$, and each edge has its weight. The unique route connecting two points is called a chain, and the length of a chain equals the sum value of the weights of the edges passed.
The point number $m$ is called the root. Lady CA defines a special kind of chain called folded chain, the chain connecting the points numbered $x,y\left(x\neq y\right)$ is called a folded chain, if and only if the chain connecting the point numbered $x$ and the root doesn't pass the point numbered $y$, and the chain connecting the point numbered $y$ and the root doesn't pass the point numbered $x$.
Lady CA wants to find the length of the $k$th longest folded chain. Notice that the chain connecting the points numbered $x,y$ and the chain connecting the points numbered $y,x$ are the same.
输入解释
The first line contains an integer $T\left(1\leq T\leq3\right)$——The number of the test cases. For each test case:
The first line contains three integers $n\left(2\leq n \leq50,000\right),m\left(1\leq m \leq n\right),k\left(1\leq k \leq\frac{n\times\left(n-1\right)}{2}\right)$. Between each two adjacent integers there is a white space separated.
The second line to the $n$th line describes the $n-1$ edges in the graph. Each line contains three integers $u,v\left(1\leq u,v\leq n,u\neq v\right),w\left(1\leq w\leq10,000\right)$, which means there is an edge which has a weight $w$ connecting the points numbered $u,v$. Between each two adjacent integers there is a white space separated.
输出解释
For each test case, the only line contains the only integer that is the length of the $k$th longest folded chain. If the $k$th longest folded chain doesn't exist, print NO.
输入样例
2
5 1 3
1 2 8
1 5 4
2 3 5
2 4 6
5 1 5
1 2 8
1 5 4
2 3 5
2 4 6
输出样例
12
NO

提示
When and only when $x=2,y=5$ or $x=3,y=5$ or $x=4,y=5$ or $x=3,y=4$, the chain connecting the point numbered $x,y$ is a folded chain. The only 4 folded chains have lengths of 12,17,18,11, so the answer of the first test case, the length of the third longest folded chain is 12.
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5664

最后修改于 2020-10-25T23:24:37+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 262144/262144K(Java/Others)