Codeforces Round #599 (Div. 2)D 边很多的只有0和1的MST
题: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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #599 (Div. 2)
久违的写篇博客吧 A. Maximum Square 题目链接:https://codeforces.com/contest/1243/problem/A 题意: 给定n个栅栏,对这n个栅栏进行任意排 ...
- Codeforces Round #599 (Div. 2) E. Sum Balance
这题写起来真的有点麻烦,按照官方题解的写法 先建图,然后求强连通分量,然后判断掉不符合条件的换 最后做dp转移即可 虽然看起来复杂度很高,但是n只有15,所以问题不大 #include <ios ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 寒假day24
数据挖掘得继续深入,人物画像需要进行更多层次的分析
- 进度3_家庭记账本App_Fragment使用SQLite实现简单存储及查询
AddFragment.java: package com.example.familybooks; import android.content.ContentValues; import andr ...
- RewriteEngine On
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond ...
- LeetCode——139. 单词拆分
给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词. 说明: 拆分时可以重复使用字典中的单词. 你可以假设字典中没有重复 ...
- input框随输入的文字的多少自动调整宽度粗略版本
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- nginx常用编译参数
./configurate --prefix=/app/tengine --user=www --group=www --with-http_v2_module --with-http_ssl_mod ...
- 在WSL Ubuntu1804中安装Docker
一.系统环境 1.1 环境准备: Windows10 企业版 1909 Docker for Windows WSL Ubuntu1804 1.2 下载安装 Docker for Windows 1. ...
- 编程作业2.2:Regularized Logistic regression
题目 在本部分的练习中,您将使用正则化的Logistic回归模型来预测一个制造工厂的微芯片是否通过质量保证(QA),在QA过程中,每个芯片都会经过各种测试来保证它可以正常运行.假设你是这个工厂的产品经 ...
- 离群点检测(Novelty Detection, Outlier Detenction)
适合问题: 对于无标签的数据, 又想找出坏用户,完成业务目标. 参考: https://scikit-learn.org/stable/modules/outlier_detection.html 算 ...
- 吴裕雄--天生自然Linux操作系统:Linux 系统目录结构
登录系统后,在当前命令窗口下输入命令: ls / 你会看到如下图所示: 树状目录结构: 以下是对这些目录的解释: /bin:bin是Binary的缩写, 这个目录存放着最经常使用的命令. /boot: ...