CF1242B.0-1 MST

普及/提高-

通过率:0%

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?

输入格式

The first line of the input contains two integers nn and mm ( 1n1051 \leq n \leq 10^5 , 0mmin(n(n1)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 ( 1ai,bin1 \leq a_i, b_i \leq n , aibia_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.

输出格式

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 .

首页