QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#600. Drzewo rozpinające o minimalnym MEX-ie

الإحصائيات

Dany jest spójny graf nieskierowany złożony z $n$ wierzchołków i $m$ krawędzi. $i$-ta krawędź ma nieujemną wagę całkowitą $w_i$. Należy znaleźć drzewo rozpinające tego grafu takie, aby mex zbioru wag krawędzi w drzewie rozpinającym był jak najmniejszy.

Wejście

Pierwszy wiersz wejścia zawiera dwie dodatnie liczby całkowite $n$ oraz $m$ ($1 \le n \le 5 \times 10^5$, $1 \le m \le 10^6$).

W kolejnych $m$ wierszach znajdują się po trzy nieujemne liczby całkowite $u$, $v$ oraz $w$ ($1 \le u, v \le n$, $u \ne v$, $0 \le w \le n-1$), oznaczające, że pomiędzy wierzchołkami $u$ i $v$ istnieje krawędź o wadze $w$.

Wyjście

Wypisz jeden wiersz zawierający jedną liczbę całkowitą — odpowiedź.

Przykład

Wejście

2 2
1 2 0
1 2 1

Wyjście

0

Wejście

5 7
1 2 0
1 3 0
2 4 1
2 5 0
3 4 2
3 5 0
4 5 1

Wyjście

1

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.