| Insomnia-26 |
|---|
| Finished |
The ancient Kingdom of Lumina consists of $$$n$$$ cities connected by $$$m$$$ bidirectional magical leylines. Each leyline possesses a base resonance, represented by an integer $$$w$$$. This resonance can be positive (harmonious), negative (dissonant), or even zero (inert).
The High Mage wishes to establish a grand unified network—a subset of exactly $$$n - 1$$$ leylines that connects all $$$n$$$ cities together so that magic can flow freely between any two cities.
The overall instability of a chosen network is defined as the product of the resonances of its constituent leylines. To prevent a catastrophic magical surge, the High Mage must select a network that minimizes this instability.
Because the leylines are powerful, the minimum instability can be an exceptionally large positive or negative number. You are tasked with finding the minimum possible instability and reporting it modulo $$$10^9 + 7$$$.
Note on Modulo Arithmetic: The answer must be the mathematically correct modulo. If the true minimum product is $$$P$$$, you should output $$$(P \pmod{10^9 + 7} + 10^9 + 7) \pmod{10^9 + 7}$$$. You are minimizing the actual integer product first, and then applying the modulo to that minimum value.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le 2 \cdot 10^5$$$) — the number of cities and the number of leylines, respectively.
Each of the following $$$m$$$ lines contains three integers $$$u$$$, $$$v$$$, and $$$w$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$, $$$-10^9 \le w \le 10^9$$$) — indicating a bidirectional leyline connecting city $$$u$$$ and city $$$v$$$ with a magical resonance of $$$w$$$.
It is guaranteed that for each test case, the given graph is simple (contains no self-loops and no multiple edges between the same pair of cities) and that it is always possible to connect all cities (the graph is connected).
It is also guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$.
For each test case, print a single integer on a new line — the minimum possible product of the edge weights of a spanning tree, modulo $$$10^9 + 7$$$.
64 51 2 22 3 -33 4 -44 1 51 3 13 31 2 -22 3 53 1 -14 41 2 22 3 33 4 41 4 54 41 2 -22 3 -33 4 -41 4 -55 51 2 -12 3 -23 4 -34 5 -45 1 -53 31 2 10000000002 3 10000000001 3 0
999999967 999999997 24 999999947 24 0
| Name |
|---|


