F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

zhx's tree

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 245    Accepted Submission(s): 17


Problem Description
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}$.
 

Input
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.
 

Output
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$)
 

Sample Input
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
 

Sample Output
3/1 5/4 907/15 1396/21 85/2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-02-17 05:38:33, Gzip enabled