#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
using namespace std;
const int N = 2e5 + 5; vector<int> result;
std::set<pair<int, int> > unExistedMap;
int nextPoint[N];
int prePoint[N];
class List {
private:
int headPoint;
void initialize(int n) {
headPoint = 1;
for (int i = 1; i <= n; ++i) {
nextPoint[i] = i + 1;
prePoint[i] = i - 1;
}
nextPoint[n] = 0;
prePoint[1] = 0;
}
void deletePoint(int pos) {
int prePos = prePoint[pos];
int nexPos = nextPoint[pos];
nextPoint[prePos] = nexPos;
prePoint[nexPos] = prePos;
if (prePos == 0)
headPoint = nexPos;
} public:
List(int n) { initialize(n); }
void Solve() {
while (1) {
if (headPoint == 0)
break;
std::queue<int> bfsQueue;
bfsQueue.push(headPoint);
deletePoint(headPoint);
int totalMapSeg = 0;
while (!bfsQueue.empty()) {
totalMapSeg++;
int nowPoint = bfsQueue.front();
bfsQueue.pop();
for (int i = headPoint; i; i = nextPoint[i]) {
int from = nowPoint;
int to = i;
if (from > to)
swap(from, to);
if (unExistedMap.find(std::make_pair(from, to)) == unExistedMap.end()) {
bfsQueue.push(i);
deletePoint(i);
}
}
}
result.push_back(totalMapSeg);
}
}
}; int main() {
int n, m;
while (~scanf("%d %d", &n, &m)) {
unExistedMap.clear();
result.clear();
for (int i = 0; i < m; ++i) {
int from, to;
scanf("%d %d", &from, &to);
if (from > to)
swap(from, to);
unExistedMap.insert(std::make_pair(from, to));
} List Basa = List(n);
Basa.Solve(); sort(result.begin(), result.end());
printf("%d\n", (int)result.size());
for (int i = 0; i < result.size(); ++i) {
printf("%d ", result[i]);
}
printf("\n");
}
return 0;
}

Educational Codeforces Round37 E - Connected Components?的更多相关文章

  1. Educational Codeforces Round 37-E.Connected Components?题解

    一.题目 二.题目链接 http://codeforces.com/contest/920/problem/E 三.题意 给定一个$N$和$M$.$N$表示有$N$个点,$M$表示,在一个$N$个点组 ...

  2. Codeforces 920 E Connected Components?

    Discription You are given an undirected graph consisting of n vertices and  edges. Instead of giving ...

  3. Educational Codeforces Round 37 E. Connected Components?(图论)

    E. Connected Components? time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  4. 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 ...

  5. Codeforces E - Connected Components?

    E - Connected Components? 思路: 补图bfs,将未访问的点存进set里 代码: #include<bits/stdc++.h> using namespace s ...

  6. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  7. [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  8. PTA Strongly Connected Components

    Write a program to find the strongly connected components in a digraph. Format of functions: void St ...

  9. LeetCode Number of Connected Components in an Undirected Graph

    原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...

随机推荐

  1. 洛谷 [p1439] 最长公共子序列 (NlogN)

    可以发现只有当两个序列中都没有重复元素时(1-n的排列)此种优化才是高效的,不然可能很不稳定. 求a[] 与b[]中的LCS 通过记录lis[i]表示a[i]在b[]中的位置,将LCS问题转化为最长上 ...

  2. BZOJ 2005: [Noi2010]能量采集 [莫比乌斯反演]

    题意:\((0,0)\)到\((x,y),\ x \le n, y \le m\)连线上的整点数\(*2-1\)的和 \((0,0)\)到\((a,b)\)的整点数就是\(gcd(a,b)\) 因为. ...

  3. 【视频编解码·学习笔记】6. H.264码流分析工程创建

    一.准备工作: 新建一个VS工程SimpleH264Analyzer, 修改工程属性参数-> 输出目录:$(SolutionDir)bin\$(Configuration)\,工作目录:$(So ...

  4. 树莓派小车(三)Python控制小车

    正文之前 由于最近忙于复习赶考,所以暂时没有拿起树莓派小车,直到昨天,终于空出时间来把代码整理一下来和大家分享. 正文 在树莓派小车系列之二中,讲到了树莓派的引脚定义方式有两种: PHYSICAL N ...

  5. Job 失败了怎么办?- 每天5分钟玩转 Docker 容器技术(133)

    上一节讨论了 Job 执行成功的情况,如果失败了会怎么样呢? 修改 myjob.yml,故意引入一个错误: 先删除之前的 Job: 如果将 restartPolicy 设置为 OnFailure 会怎 ...

  6. 关于在jsp中的路径问题

    前言: jsp作为javaweb开发中常见的视图技术,我们平时在开发项目使用的过程中,经常会导入一些静态资源,比如css\js\jpg.png等图片格式的文件,这些文件的路径成了问题,经常会出现索引不 ...

  7. Java String使用总结

    1 == 与 equals() 使用==来比较两个primitive主数据类型在意义上相等(是否带有相同的字节组合),或者判断两个引用(如String变量)是否引用同一个对象.使用equals()来判 ...

  8. CentOS6搭建OpenVPN服务器

    一.服务器端安装及配置 服务器环境:干净的CentOS6.3 64位系统 内网IP:10.143.80.116 外网IP:203.195.xxx.xxx OpenVPN版本:OpenVPN 2.3.2 ...

  9. Python基础——条件判断

    Python版本:3.6.2  操作系统:Windows  作者:SmallWZQ 到目前为止,Python基础系列的文章中的程序都是一条一条语句顺序执行的.在本章中,我会重点介绍让程序选择是否执行语 ...

  10. 抛砖引玉之~sftp

    跨平台系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#linux XFtp用惯了,没有它就不行了?Linux就不能文件传输了? 答案肯定是~No ...