Politicians
Time limit1sMemory limit1024 MB
Given ratio relations between politicians that form a connected comparison graph, find the most and least important and their importance ratio to two decimals.
- Level
Medium6 of 10
- Topics
- Graph, DFS, Union-find, Math
- Solved
- No attempts yet
Problem
In a certain country, someone proposed abolishing elections and instead assigning public offices according to each politician's "importance".
You are given several importance relations between politicians. Each relation states how many times more important one politician is than another. These relations satisfy the following properties:
- If politician A is times as important as B, and B is times as important as C, then A is times as important as C.
- If politician A is times as important as B, then B is times as important as A.
Assume the input contains no contradictions and that the given relations are enough to compare the importance of every pair of politicians.
Find the most important politician, the least important politician, and how many times more important the most important one is than the least important one.
Input
The first line contains the number of importance relations ().
Each of the next lines contains the names of two politicians and an integer (), separated by spaces. It means the first politician is times as important as the second.
Each politician's name is at most 10 characters long and consists only of lowercase letters and digits (no uppercase letters, spaces, or other characters).
Output
Print three values on one line, separated by spaces:
- The name of the most important politician. If several politicians share the maximum importance, print the lexicographically smallest of their names.
- The name of the least important politician. If several politicians share the minimum importance, print the lexicographically smallest of their names.
- The value telling how many times more important the most important politician is than the least important one, rounded to exactly two decimal places (round half up). It is guaranteed that .
The input is chosen so that never lands on a rounding boundary at two decimal places, so the rounded result is always unambiguous.