This page is still under construction.

Parts of this page are still being built. What you see may change.

Politicians

Time limit1sMemory limit1024 MB

Summary
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 xx times as important as B, and B is yy times as important as C, then A is x⋅yx \cdot y times as important as C.
  • If politician A is xx times as important as B, then B is 1x\frac{1}{x} 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 NN (1≤N≤1000001 \le N \le 100000).

Each of the next NN lines contains the names of two politicians and an integer XX (1≤X<2321 \le X < 2^{32}), separated by spaces. It means the first politician is XX 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:

  1. The name of the most important politician. If several politicians share the maximum importance, print the lexicographically smallest of their names.
  2. The name of the least important politician. If several politicians share the minimum importance, print the lexicographically smallest of their names.
  3. The value YY 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 Y<232Y < 2^{32}.

The input is chosen so that YY never lands on a rounding boundary at two decimal places, so the rounded result is always unambiguous.

Examples1

  1. Example 1

    Input
    3
    albert bruno 3
    charlie bruno 2
    charlie dennis 5
    
    Expected output
    albert dennis 7.50