Under construction

Still being built. Things may change

Bickford Fuse

Interview

Time limit2sMemory limit1024 MB

Summary
Given a graph of knots and ropes with burn times, find the knot whose lighting lets the whole fuse burn out in the least time, and report that time.
Level

Medium5 of 10

Topics
Shortest path, Graph
Solved
No attempts yet

Statement

On a sunny day, Hedgehog was walking through his favorite clearing when he noticed something unusual that had never been there before. From a distance it looked like a ball of tangled ropes. Up close, after he untangled it and examined the material, Hedgehog concluded that it was a Bickford fuse.

Hedgehog saw that whoever made it must have been bored and had a lot of free time. The fuse was knotted, and it had a huge number of knots! After counting carefully, he found that there are nn knots and mm connections between them. Each connection joins two knots and burns at a uniform rate. When a knot is lit, all connections that contain it start to burn.

Hedgehog did not like the find, so he decided to destroy it. He had a match in his pocket that he had forgotten about. He can light one of the knots with it, and the whole structure starts to burn. Hedgehog is a busy hedgehog and wants the structure to burn as fast as possible. Help him determine which knot he should light.

Input

The first line contains two integers nn and mm (2≤n≤1002 \le n \le 100, 1≤m≤n⋅(n−1)21 \le m \le \frac{n \cdot (n - 1)}{2}), the number of knots and the number of ropes between them.

Each of the next mm lines contains three integers aia_i, bib_i, and tit_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \neq b_i, 1≤ti≤10001 \le t_i \le 1000), the numbers of the knots joined by the ii-th rope and the number of seconds that rope takes to burn completely when lit from one of its ends.

Each pair of knots is joined by at most one rope. It is guaranteed that the whole fuse can burn if any one of its knots is lit.

Output

Print a pair of numbers: the number of the knot to light, and the time it takes for the whole fuse to burn when lit at that knot.

Examples1

  1. Example 1

    Input
    4 4
    1 2 3
    2 3 4
    1 3 5
    1 4 1
    
    Expected output
    2 4