CF1242B.0-1 MST

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.

It is an undirected weighted graph on nn vertices. It is a complete graph: each pair of vertices is connected by an edge. The weight of each edge is either 00 or 11; exactly mm edges have weight 11, and all others have weight 00.

Since Ujan doesn't really want to organize his notes, he decided to find the weight of the minimum spanning tree of the graph. (The weight of a spanning tree is the sum of all its edges.) Can you find the answer for Ujan so he stops procrastinating?

乌詹的抽屉里堆满了各种无用的东西,其中相当一部分是他的数学笔记:是时候整理一下了。这次他发现了一本陈旧积灰的图论笔记,上面描述了一个图。

这是一个含有 nn 个顶点的无向带权图。该图是完全图:任意两个顶点之间都有一条边相连。每条边的权重为 00 或 11;其中恰好有 mm 条边的权重为 11,其余所有边的权重均为 00。

由于乌詹并不真的想整理自己的笔记,他决定计算该图的最小生成树(MST)的权重。(生成树的权重定义为其中所有边的权重之和。)你能帮乌詹算出这个答案,好让他停止拖延吗?

输入格式

The first line of the input contains two integers nn and mm (1≤n≤1051 \leq n \leq 10^5, 0≤m≤min⁡(n(n−1)2,105)0 \leq m \leq \min(\frac{n(n-1)}{2},10^5)), the number of vertices and the number of edges of weight 11 in the graph.

The ii-th of the next mm lines contains two integers aia_i and bib_i (1≤ai,bi≤n1 \leq a_i, b_i \leq n, ai≠bia_i \neq b_i), the endpoints of the ii-th edge of weight 11.

It is guaranteed that no edge appears twice in the input.

输入的第一行包含两个整数 nn 和 mm(1≤n≤1051 \leq n \leq 10^5,0≤m≤min⁡(n(n−1)2,105)0 \leq m \leq \min(\frac{n(n-1)}{2},10^5)),分别表示图中顶点的数量以及权值为 11 的边的数量。

接下来的 mm 行中,第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,ai≠bia_i \neq b_i),表示第 ii 条权值为 11 的边的两个端点。

保证输入中不会出现重复的边。

输出格式

Output a single integer, the weight of the minimum spanning tree of the graph.

输出一个整数,表示该图的最小生成树的权重。

输入输出样例

  • 输入#1

    6 11
    1 3
    1 4
    1 5
    1 6
    2 3
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6

    输出#1

    2
  • 输入#2

    3 0

    输出#2

    0

说明/提示

The graph from the first sample is shown below. Dashed edges have weight 00, other edges have weight 11. One of the minimum spanning trees is highlighted in orange and has total weight 22.

In the second sample, all edges have weight 00 so any spanning tree has total weight 00.

第一个样例的图如下所示。虚线边的权重为 00,其余边的权重为 11。其中一棵最小生成树以橙色高亮显示,其总权重为 22。

在第二个样例中,所有边的权重均为 00,因此任意一棵生成树的总权重均为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页