Given a directed graph where each edge has a nonnegative weight, and a root vertex $$$r$$$, the directed minimum spanning tree problem asks to choose a subset of edges such that:
Although there exist efficient algorithms for computing the directed minimum spanning tree, we look at a simple special case in this problem. Given is a directed graph with $$$n$$$ vertices and $$$m$$$ directed edges. The vertices are indexed $$$1 \ldots n$$$. All edges, except for exactly one, are directed from the vertex with the smaller index to the vertex with the bigger index. There are no parallel edges, i.e. for every pair of vertices $$$(u, v)$$$, there is at most one edge $$$u \to v$$$. Find the directed minimum spanning tree, with root vertex 1.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. $$$t$$$ test cases follow. Each test case is described as follows.
The first line of the test case consists of two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le 5 \cdot 10^5$$$). The following $$$m$$$ lines each consist of three integers $$$u$$$, $$$v$$$ and $$$w$$$, denoting an edge $$$u \to v$$$ with weight $$$w$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$, $$$0 \le w \le 10^9$$$). For all but one of these lines $$$u \lt v$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$ and the sum of $$$m$$$ over all test cases doesn't exceed $$$5 \cdot 10^5$$$.
The tests are constructed in such a way that a directed spanning tree always exists.
For each test case, print the answer on a separate line — a single integer, the total weight of edges in the directed minimum spanning tree.
35 61 2 41 3 22 3 03 4 14 5 15 2 14 41 2 41 3 61 4 84 2 10000003 31 2 1002 1 102 3 1000
5 18 1100
The figure below illustrates the first example test case. The solid edges are the ones in the directed minimum spanning tree. Notice that if we didn't use the backwards edge, the total weight would have to be at least 6.
In the second example, the backwards edge has a very high weight, so there is no point in considering it.
Notice that although the statement guarantees that there are no parallel edges, antiparallel edges (such as seen in the third example) are allowed.
| Название |
|---|


