Problem B
Buildin' Roads
Old Man Joe has been tasked with building bidirectional roads to connect $N$ locations. Each road requires some quantity of two different materials to build, pitch and gravel. On one hand, pitch is in short supply from all the tarring-and-feathering that has recently happened. On the other hand, the county has a surplus of gravel just sitting around and needs to be used.
Joe is less worried about the total material spent creating the roads and is more concerned with being efficient with the scarce supply of pitch and ample supply of gravel. He wants to build roads to minimize the ratio between the total pitch used to the total gravel used to give the appearance of being efficient. But one thing is certain, he will get tarred and feathered himself if he builds more than $N-1$ roads in total. Help Old Man Joe come up with the best solutions.
Input
The first line of input contains two integers $N$ ($2 \leq N \leq 2 \cdot 10^4$) and $M$ ($N-1 \leq M \leq 2 \cdot 10^5$). Here, $N$ is the number of locations (numbered from $1$ to $N$) and $M$ is the number of possible bidirectional roads that can be built.
Then $M$ lines follow, the $i$th such line consists of four integers $u_ i, v_ i, p_ i$ and $g_ i$. This means the $i$th road would run between locations $u_ i$ and $v_ i$ and would require both $p_ i$ pounds of pitch and $g_ i$ pounds of gravel. These values satisfy $1 \leq u_ i, v_ i \leq N$ and $u_ i \neq v_ i$ and also $1 \leq p_ i, g_ i \leq 10^5$. Note, there may be multiple edges connecting two different locations. You may assume that it is possible to build $N-1$ roads to connect the $N$ locations.
Output
Print a single fraction giving the minimum possible ratio $P/G$ pounds of pitch used $(P)$ to pounds of gravel used $(G)$ to connect the locations using exactly $n-1$ roads.
This fraction should be printed in reduced form with the numerator and denominator being separated by a single / character. Even if the answer is an integer, you should still print a $1$ for the denominator. Do not include any spaces between the numerator, / character, or denominator.
Sample Input 1 | Sample Output 1 |
---|---|
3 3 1 2 1 2 2 3 2 4 1 3 3 7 |
4/9 |
Sample Input 2 | Sample Output 2 |
---|---|
6 7 1 2 10 10 2 3 10 50 1 3 50 50 4 5 10 10 5 6 10 50 4 6 50 200 1 6 1 1 |
81/311 |
Sample Input 3 | Sample Output 3 |
---|---|
2 3 1 2 20 18 1 2 5 4 1 2 2001 1000 |
10/9 |
Sample Input 4 | Sample Output 4 |
---|---|
3 3 1 2 12 6 2 3 14 7 3 1 22 11 |
2/1 |
Sample Input 5 | Sample Output 5 |
---|---|
4 4 1 2 2 7 1 3 1 1 1 4 99 100 4 3 10 20 |
13/28 |