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 n 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 m 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?

Input

The first line of the input contains two integers n and m (1≤≤1051≤n≤105, 0≤≤min((−1)2,105)0≤m≤min(n(n−1)2,105)), the number of vertices and the number of edges of weight 11 in the graph.

The i-th of the next m lines contains two integers ai and bi (1≤,≤1≤ai,bi≤n, ≠ai≠bi), the endpoints of the i-th edge of weight 11.

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

Output

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

Examples
input

Copy

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

output

Copy

2

input

Copy

3 0

output

Copy

0

Note

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.

题意:完全图,给出一部分,求补图连通分量个数.

答案为连通分量个数减1, 用bitset优化太巧妙了~~~

对于每一个点(没有被访问过),枚举不和它相连并且没有访问过的点,依次dfs下去,得到一个连通分量.

#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
map<int,bool>mp[maxn];
bitset<maxn>bit;
void dfs(int u){
bit[u] = 0;
for(int i = bit._Find_first();i < bit.size();i = bit._Find_next(i)){
if(!mp[u][i])dfs(i);
}
}
int main()
{
int n,m;
cin >> n >> m;
for(int i = 1;i <= m;i++){
int u,v;
cin >> u >> v;
mp[u][v] = mp[v][u] = 1;
}
for(int i = 1;i <= n;i++)bit[i] = 1;
int sum = 0;
for(int i = 1;i <= n;i++){
if(bit[i])dfs(i),sum++;
}
cout << sum - 1 << endl;
return 0;
}

CodeForces - 1243D. 0-1 MST(补图连通分量个数)的更多相关文章

  1. SDUT 1488 数据结构实验:连通分量个数

    数据结构实验:连通分量个数 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description  在无向图中,如 ...

  2. SDUT OJ 之 连通分量个数 (dfs)

    数据结构实验:连通分量个数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  在无向图中,如果从顶点vi到顶点vj有路径,则称vi ...

  3. UVA 1640 The Counting Problem UVA1640 求[a,b]或者[b,a]区间内0~9在里面各个数的数位上出现的总次数。

    /** 题目:UVA 1640 The Counting Problem UVA1640 链接:https://vjudge.net/problem/UVA-1640 题意:求[a,b]或者[b,a] ...

  4. [ActionScript 3.0] AS3 获取函数参数个数

    function createFunction(param1:String,param2:String,param3:int=0):void { trace(arguments.length);//a ...

  5. 调用类java.lang.Math的成员方法"public static double random"运算下面表达式10000次,统计其中生成的整数0,1,2,.....20的个数分别是多少,并输出统计结果.(int)(Math.random()*20+0.5)

    public class Test2 { public static void main(String args[]){ int num; int count[]=new int[21]; for(i ...

  6. CodeForces - 1243D (思维+并查集)

    题意 https://vjudge.net/problem/CodeForces-1243D 有一张完全图,n个节点 有m条边的边权为1,其余的都为0 这m条边会给你 问你这张图的最小生成树的权值 思 ...

  7. 求0到n之间素数个数的序列

    要求: (1) 找出0-1000之间素数(2) 设f(n)表示0-n之间的素数个数,计算出当n=0,1,2,3,.....,997时f(n)的值,并写入文件 分析: 首先找素数使用一个效率较高的方法- ...

  8. 数组中的数分为两组,让给出一个算法,使得两个组的和的差的绝对值最小,数组中的数的取值范围是0<x<100,元素个数也是大于0, 小于100 。

    比如a[]={2,4,5,6,7},得出的两组数{2,4,6}和{5,7},abs(sum(a1)-sum(a2))=0: 比如{2,5,6,10},abs(sum(2,10)-sum(5,6))=1 ...

  9. Codeforces 196E Opening Portals MST (看题解)

    Opening Portals 我们先考虑如果所有点都是特殊点, 那么就是对整个图求个MST. 想在如果不是所有点是特殊点的话, 我们能不能也 转换成求MST的问题呢? 相当于我们把特殊点扣出来, 然 ...

随机推荐

  1. 一、JavaScript之第一个实例,点击按钮修改文本内容

    一.代码如下: 二.运行后效果如下 三.点击按钮,"曾经沧海难为水"变成了日期事件了 <!DOCTYPE html> <html> <meta htt ...

  2. python 第一节 脚本 import from reload exec

    环境Ubuntu 14.04, 不写交互式命令行了,直接脚本开始. # first Python script import sys print(sys.platform) print(2**4) x ...

  3. yarn调度器 FairScheduler 与 CapacityScheduler

    yarn FairScheduler 与 CapacityScheduler CapacityScheduler(根据计算能力调度) CapacityScheduler 允许多个组织共享整个集群, 每 ...

  4. 《百面机器学习算法工程师带你去面试》高清PDF及epub+《美团机器学习实践》PDF及思维导图

    http://blog.sina.com.cn/s/blog_ecd882db0102yuek.html <百面机器学习算法工程师带你去面试>高清PDF及epub+<美团机器学习实践 ...

  5. 剑指offer_1.19_Day_3

    替换空格 请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. Javascript_V8 f ...

  6. 详解contextConfigLocation|Spring启动过程详解(转)

    原文链接:https://blog.csdn.net/qw222pzx/article/details/78191670 spring的应用初始化流程一直没有搞明白,刚刚又碰到了相关的问题.决定得好好 ...

  7. URAL_1018 Binary Apple Tree 树形DP+背包

    这个题目给定一棵树,以及树的每个树枝的苹果数量,要求在保留K个树枝的情况下最多能保留多少个苹果 一看就觉得是个树形DP,然后想出 dp[i][j]来表示第i个节点保留j个树枝的最大苹果数,但是在树形过 ...

  8. CSS position定位属性

    css中的position属性是用于设置元素位置的定位方式 它有以下几种取值: static:默认定位方式,子容器在父容器中按照默认顺序进行摆放 absolute:绝对定位,元素不占据父容器空间,相当 ...

  9. 从单个系统到云翼一体化支撑,京东云DevOps推进中的一波三折

    作者:王利莹 采访嘉宾:京东云DevOps团队负责人 郑永宽 今年,IDC 特别针对中国地区发布了<IDC MarketScape:中国 DevOps 云市场2019,厂商评估>研究报告, ...

  10. js事件函数中function(e){}

    简单来说就是指向了当前发生的事件(click.mouseover等等),保存了当前事件的信息.如鼠标点击事件,有鼠标的坐标信息.其中,e是标准浏览器传递进去的事件参数,低版本IE不会传递,事件参数放置 ...