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

建议使用的浏览器:

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

5189:zhx's tree

题目描述
zhx has built a tree of $n$ nodes. On each node of the tree live a boy and a girl. The weight and height of them are already known.
One day, zhx was bored of brushing problems, so he asked you to find a boy and a girl on the path between u and v (not necessary to live on the same node). He wants you to maximize the weighted average height of them.
Note: Let's assume that the boy's weight is $wb$ and his height is $hb$, and the girl's weight is $wg$ and her height is $hg$, then the answer should be $\frac{wb * hb + wg * hg}{wb + wg}$.
输入解释
Multiply test cases(less than $10$. Cases in which $n > {10}^{4}$ will not exceed $3$). Seek $EOF$ as the end of the file.
For each case, there are two integers $n, q$ in the first line.($n,q \leq 3*10^{4}$)
In the following $n$ lines, there are four integers $wb_i, hb_i, wg_i, hg_i$($1 \leq wb_i, hb_i, wg_i, hg_i \leq 10^{3}$), indicating the weight and the height of the boy and the girl on node $i$.
Then comes $n - 1$ lines with two integers, indicating edges of the tree.(nodes are numbered from $1$ to $n$)
Then comes $q$ lines with two integers $u, v$ indicating an query.
输出解释
For each query, output a simplified fraction as the answer.(That means if your answer is $\frac{a}{b}$, $a$ and $b$ should not have a common divisor larger than $1$)
输入样例
3 2
1 2 3 1
2 3 1 2
2 3 3 3
1 2
1 3
1 3
1 1
4 3
32 21 51 32
51 53 48 1
16 61 5 84
89 5 84 65
1 2
2 3
2 4
4 1
3 2
1 2
输出样例
3/1
5/4
907/15
1396/21
85/2
来自杭电HDUOJ的附加信息
Recommend hujie

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

题目来源 BestCoder Round #33

源链接: HDU-5189

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

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 65536/65536K(Java/Others)