Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓
統計

奇妙なことに、自然に考えられそうな規則であるにもかかわらず、以前に存在していた例を一つも見つけられないことは、私でさえ奇妙に思います。あちらこちらにある問題の中には少し似たものもありますが、それでも、まったく同じものは一つもありません。なんと奇妙な。あるいは偶数の。

— Sam Cappleman-Lynes

頂点数 $n$、辺数 $m$ の無向グラフが与えられます。$T$ をこのグラフの全域木とし、$\mathrm{Cost}(T)$ を $T$ に含まれるすべての辺の重みの総和とします。次の条件を満たす $T_1$ と $T_2$ を求めてください。

  • $\mathrm{Cost}(T_1)$ が偶数で、$\mathrm{Cost}(T_1)$ が最小です。
  • $\mathrm{Cost}(T_2)$ が奇数で、$\mathrm{Cost}(T_2)$ が最小です。

入力

最初の行には、テストケース数を表す一つの整数 $T$ ($1 \le T \le 10^4$) が含まれます。各テストケースについて、次の形式で与えられます。

最初の行には、頂点数と辺数を表す二つの整数 $n$ と $m$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m \le 5 \cdot 10^5$) が含まれます。

続く $m$ 行にはそれぞれ、無向辺を表す三つの整数 $u_i, v_i$, $w_i$ ($1 \le u_i, v_i \le n$, $u_i \neq v_i$, $1 \le w_i \le 10^9$) が含まれます。

すべての $n$ の総和は最大 $2 \cdot 10^5$、すべての $m$ の総和は最大 $5 \cdot 10^5$ であることが保証されます。

出力

各テストケースについて、二つの整数 $\mathrm{Cost}(T_1)$ と $\mathrm{Cost}(T_2)$ を 1 行に出力してください。そのような全域木が見つからない場合は、そのコストの代わりに -1 を出力してください。

入出力例

入力 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

出力 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.