题:https://codeforces.com/contest/1243/problem/D

分析:找全部可以用边权为0的点连起来的全部块

   然后这些块之间相连肯定得通过边权为1的边进行连接

   所以答案就是这些块的总数-1;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int M=1e5+;
set<int>s,g[M];
int vis[M];
void bfs(int x){
queue<int>que;
que.push(x);
s.erase(x);
while(!que.empty()){
int u=que.front();
que.pop();
if(vis[u])
continue;
vis[u]=;
set<int>::iterator it;
for(it=s.begin();it!=s.end();){
int v=*it;
it++;
if(g[u].find(v)==g[u].end()){///如果这一次找不到的话,就说明这个块中的点有流向它的权值为1的边
que.push(v);
s.erase(v); }
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
s.insert(i);
for(int x,y,i=;i<=m;i++){
scanf("%d%d",&x,&y);
g[x].insert(y);
g[y].insert(x);
}
int ans=;
for(int i=;i<=n;i++){
if(!vis[i]){
ans++;
bfs(i);
}
}
printf("%d\n",ans-);
}

Codeforces Round #599 (Div. 2)D 边很多的只有0和1的MST的更多相关文章

  1. Codeforces Round #599 (Div. 2) D. 0-1 MST(bfs+set)

    Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers ...

  2. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset (0/1-Trie树)

    Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out ...

  3. Codeforces Round #599 (Div. 2)

    久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...

  4. Codeforces Round #599 (Div. 2) E. Sum Balance

    这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <ios ...

  5. Codeforces Round #599 (Div. 1) C. Sum Balance 图论 dp

    C. Sum Balance Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to ...

  6. Codeforces Round #599 (Div. 1) B. 0-1 MST 图论

    D. 0-1 MST Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math ...

  7. Codeforces Round #599 (Div. 1) A. Tile Painting 数论

    C. Tile Painting Ujan has been lazy lately, but now has decided to bring his yard to good shape. Fir ...

  8. Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造

    B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...

  9. Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version) 水题

    B1. Character Swap (Easy Version) This problem is different from the hard version. In this version U ...

随机推荐

  1. [极客大挑战 2019]FinalSQL

    0x00 知识点 盲注 0x01 解题 根据题目提示盲注,随便点几下找到注入点 发现我们输入^符号成功跳转页面,证明存在注入 1^(ord(substr((select(group_concat(sc ...

  2. Zookeeper--命令介绍

    参考 https://zookeeper.apache.org/doc/r3.4.13/zookeeperStarted.html#sc_ConnectingToZooKeeper 连接到zookee ...

  3. openstack trove主要贡献公司-Tesora被Stratoscale收购

    新闻链接:http://www.stratoscale.com/press/press-releases/stratoscale-acquires-database-as-a-service-prov ...

  4. 【收藏】免费开源好看的bootstrap后台模板

    1.ace admin github:https://github.com/bopoda/acedemo:http://ace.jeka.by/ 2.CoreUI jQuery.Angular.Rea ...

  5. 【十日冲刺计划】第一日 星遇Sprint1计划会议成果

    ——小组成员 赵剑峰 张傲 周龙海 Sprint 计划会议1:定出 Sprint 目标和既定产品Backlog. 会议进程(1小时) • 首先对sprint目标进行总体介绍,概括星遇的backlog, ...

  6. 对比Node.js和Python 帮你确定理想编程解决方案!

    世上没有最好的编程语言.有些编程语言比其他编程语言用于更具体的事情.比如,你可能需要移动应用程序,网络应用程序或更专业化的系统,则可能会有特定的语言.但是我们暂时假设你需要的是一个相对来说比较简单的网 ...

  7. E. Double Elimination (DP)

    题目:传送门 题意:有 2^n 个人进行比赛,对他们编号 1~2^n,起初1和2打,3和4打,5和6打,7和8打...,然后1和2打完胜利的 和 3和4打完胜利的再打一场,1和2打完失败的和3和4打完 ...

  8. 吴裕雄--天生自然 JAVASCRIPT开发学习:(String) 对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 0CTF-2016-piapiapia-PHP反序列化长度变化尾部字符串逃逸

    0X00 扫描一下网站目录,得到网站源码,这里说下工具使用的是dirmap,亲测御剑不好用... 0x01 审计源码: index.php <?php require_once('class.p ...

  10. Linux 杀掉所有Java进程

      ps -ef | grep java | grep -v grep | awk '{print $2}' | xargs kill -9 管道符"|"用来隔开两个命令,管道符左 ...