There are n towns conveniently labeled with 1, 2, ..., n in Flatland Kingdom and m bidirectional highways are allowed to be built.
The i-th highway can be built between cities a[i]
and b[i]
with cost c[i]
.
The Flatland Road Company plans to build the (n - 1) allowed highways with the least total cost to connect any of two cities directly or indirectly.
The King of Flatland is going to remove some of the highways from the list of the allowed highways. Hewould like to know the minimum number of highways to be removed to strictly increase the total cost.
Note that the total cost is considered as +∞ if no valid (n - 1) highways exist after removing. It is also counted as <<total cost strictly increases>>.
Contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains two integers n (2 ≤ n ≤ 50) and m (n - 1 ≤ m ≤ n^2
). The i-th of the following m lines contains a[i]
, b[i]
, c[i]
(1 ≤ a[i]
, b[i]
≤ n, 1 ≤ c[i]
≤ 10^9
).
Any two cities will be connected if all m allowed highways are built.
The sum of n does not exceed 10^3
.
For each case, output an integer which denotes the result.