Connected Components? CodeForces - 920E (bfs)
大意:给定无向图, 求补图的连通块数
bfs模拟即可, 用了map存图, set维护未划分的点集, 复杂度$O(nlog^2n)$, 用链表的话可以$O(n)$
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back using namespace std; const int N = 4e5+, INF = 0x3f3f3f3f;
int n, m;
map<int,int> a[N];
set<int> s;
int sz[N]; int main() {
scanf("%d%d", &n, &m);
REP(i,,m) {
int u, v;
scanf("%d%d", &u, &v);
a[u][v]=a[v][u]=;
}
REP(i,,n) s.insert(i);
REP(i,,n) if (s.count(i)) {
queue<int> q;
q.push(i);
int cnt = ;
while (!q.empty()) {
int i=q.front();q.pop();
vector<int> tmp;
for (int j:s) if (!a[i][j]) {
++cnt, q.push(j), tmp.pb(j);
}
for (int j:tmp) s.erase(j);
}
sz[++*sz] = cnt;
}
printf("%d\n", *sz);
sort(sz+,sz++*sz);
REP(i,,*sz) printf("%d ",sz[i]);
puts("");
}
Connected Components? CodeForces - 920E (bfs)的更多相关文章
- Connected Components? Codeforces - 920E || 洛谷 P3452 &&bzoj1098 [POI2007]BIU-Offices
https://codeforces.com/contest/920/problem/E https://www.luogu.org/problemnew/show/P3452 https://www ...
- 线段树 C - Connected Components? CodeForces - 920E
这个题目居然可以用线段树写,好震惊,如果不是在线段树专题肯定想不到,但是就算在线段树的专题里面,我也不太会怎么写. 这个题目大意是,给你n m n代表n个点,m代表m条边,然后就是m行,每行两个数字, ...
- Codeforces E - Connected Components?
E - Connected Components? 思路: 补图bfs,将未访问的点存进set里 代码: #include<bits/stdc++.h> using namespace s ...
- Codeforces 920 E Connected Components?
Discription You are given an undirected graph consisting of n vertices and edges. Instead of giving ...
- Educational Codeforces Round 37 E. Connected Components?(图论)
E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 图论
E. Connected Components? You are given an undirected graph consisting of n vertices and edges. Inste ...
- LeetCode Number of Connected Components in an Undirected Graph
原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...
- Cyclic Components CodeForces - 977E(DFS)
Cyclic Components CodeForces - 977E You are given an undirected graph consisting of nn vertices and ...
- LeetCode 323. Number of Connected Components in an Undirected Graph
原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...
随机推荐
- Linux中Postfix基于SSL收发邮件(九)
其中在整个一套邮件服务器中,默认信息传输都是明文传输的,所以这个在安全性上面就不是那么好.但是如果说一封邮件从发生到对方接受想要全程做到加密处理这个也是很难的.因为一封邮件从一个域转到另外一个域服务器 ...
- (二)github的价值意义篇
为什么需要社会化编程? 如果您是程序员面试官,两者之间你会选择哪一位呢? 能查看以前所写代码的程序员 or 无法查看的程序员 精通最新软件的程序员 or 不精通的程序员 对语言或软件差异带来的不同文化 ...
- nginx服务器的rewrite功能
nginx编译的时候默认是把rewrite功能编辑进去的,但是因为rewrite需要使用正则表达式,因此需要安装pcre依赖包. yum install -y pcre pcre-install re ...
- 04: 事件驱动、五种I/O操作、I/O多路复用select和epoll
网络编程其他篇 目录: 1.1 事件驱动 1.2 五种I/O操作 1.3 I/O 多路复用之select.poll.epoll详解 1.1 事件驱动返回顶部 1.什么是事件驱动 定义:就是根据不同事 ...
- ELK之logstash6.5
首先安装,这里采用rpm安装: # rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch 创建repo文件: [root@no ...
- 20145314郑凯杰《网络对抗技术》PE文件病毒捆绑(插入捆绑)的实现
20145314郑凯杰<网络对抗技术>PE文件病毒捆绑(插入捆绑)的实现 一.本节摘要 简介:每个应用程序内部都有一定的空间(因为文件对齐余留的00字段)可以被利用,这样就可以保证被插入的 ...
- 20135234mqy-——信息安全系统设计基础第九周学习总结
第十章 系统级I/O 10.1 Unix I/O 一个Unix文就是一个m个字节的序列 Unix:将设备映射为文件的方式,允许Unix内核引出一个简单低级的应用接口 能够使得所有输入输出都能以一种统一 ...
- STM32.定时器
一.定时器分类 11个定时器: 定时器: 1.8 高级(7路PWM输出) 2.3.4.5 通用(4路) 6.7 基本 2个看门狗 1个sysTick 时钟分布: 二.这里我们主要对定时器中 定 ...
- Zigbee学习
(一)Zigbee简介和开发环境快速建立(IAR) 1.我不是很清楚控制链条,对于Zigbee不是太清楚 答案:CC2530 芯片上集成了 8051 内核(增强型) 2.性能特点:低速率远距离,这造就 ...
- mpvue小程序开发入门级指南
报错指南 "Error: ERR_GET_SESSION_KEY {"code":5100,"message":"(-1)服务内部错误,请稍 ...