Universal Cup Judging System

Universal Cup

Süre Sınırı: 2.0 s Bellek Sınırı: 512 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

Oddly, even I find it odd that even though this seems like a natural rule to consider, I haven't even been able to find a single example of it existing previously. The odd problem here and there even resembles it a little bit, but even so, none of them are quite the same. How odd. Or even.

— Sam Cappleman-Lynes

You are given an undirected graph with $n$ vertices and $m$ edges. Assume $T$ is a spanning tree of this graph, and let's denote $\mathrm{Cost}(T)$ as the total weights of all the edges in $T$. Please find $T_1$ and $T_2$ such that:

  • $\mathrm{Cost}(T_1)$ is even, and $\mathrm{Cost}(T_1)$ is minimized.
  • $\mathrm{Cost}(T_2)$ is odd, and $\mathrm{Cost}(T_2)$ is minimized.

Input

The first line contains a single integer $T$ ($1 \le T \le 10^4$), the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m \le 5 \cdot 10^5$), denoting the number of vertices and the number of edges.

Each of the following $m$ lines contains three integers $u_i, v_i$ and $w_i$ ($1 \le u_i, v_i \le n$, $u_i \neq v_i$, $1 \le w_i \le 10^9$), describing an undirected edge.

It is guaranteed that the sum of all $n$ is at most $2 \cdot 10^5$, and the sum of all $m$ is at most $5 \cdot 10^5$.

Output

For each test case, output a single line containing two integers: $\mathrm{Cost}(T_1)$ and $\mathrm{Cost}(T_2)$. Note that if you can't find such a spanning tree, please print -1 as the cost instead.

Examples

Input 1

3
2 1
1 2 5
3 1
1 3 1
4 4
1 2 1
1 3 1
1 4 1
2 4 2

Output 1

-1 5
-1 -1
4 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.