QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#21979. 最小生成树

统计

题目描述

给定结点数为 $n$,边数为 $m$ 的带权无向连通图 $G$,所有结点编号为 $1,2,\cdots,n$。

求 $G$ 的最小生成树的边权和。

输入格式

第一行两个正整数 $n,m$。

之后的 $m$ 行,每行三个正整数 $u_i,v_i,w_i$($1\le u_i,v_i\le n$,$0\le w_i\le 10^9$),描述一条连接结点 $u_i$ 和 $v_i$,边权为 $w_i$ 的边。

输出格式

一个整数表示 $G$ 的最小生成树的边权和。

样例数据

样例输入

7 12
1 2 9
1 5 2
1 6 3
2 3 5
2 6 7
3 4 6
3 7 3
4 5 6
4 7 2
5 6 3
5 7 6
6 7 1

样例输出

16

子任务

$1\le n\le 2\times 10^5$,$0\le m\le 5\times 10^5$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.