#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. hdu 5730 Shell Necklace [分治fft | 多项式求逆]

    hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治 ...

  2. poj1265&&2954 [皮克定理 格点多边形]【学习笔记】

    Q:皮克定理这种一句话的东西为什么还要写学习笔记啊? A:多好玩啊... PS:除了蓝色字体之外都是废话啊...  Part I 1.顶点全在格点上的多边形叫做格点多边形(坐标全是整数) 2.维基百科 ...

  3. POJ1269 Intersecting Lines[线段相交 交点]

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15145   Accepted: 66 ...

  4. BZOJ 3669: [Noi2014]魔法森林 [LCT Kruskal | SPFA]

    题目描述 为了得到书法大家的真传,小 E 同学下定决心去拜访住在魔法森林中的隐 士.魔法森林可以被看成一个包含 n 个节点 m 条边的无向图,节点标号为 1,2,3,…,n,边标号为 1,2,3,…, ...

  5. Linux C 一个简单的线程池程序设计

    最近在学习linux下的编程,刚开始接触感觉有点复杂,今天把线程里比较重要的线程池程序重新理解梳理一下. 实现功能:创建一个线程池,该线程池包含若干个线程,以及一个任务队列,当有新的任务出现时,如果任 ...

  6. js跨域解决方案

    1.参考该文档:http://blog.csdn.net/enter89/article/details/51205752 2. 参考网络:http://www.ruanyifeng.com/blog ...

  7. Windows Server 2016-部署RODC只读域控制器

    只读域控制器Read-Only Domain Controller简称RODC.RODC是Windows Server 2008之后引入的一活动目录特性,与其他域控制器一样包含AD数据库,但RODC默 ...

  8. 高可用Redis服务架构分析与搭建

    基于内存的Redis应该是目前各种web开发业务中最为常用的key-value数据库了,我们经常在业务中用其存储用户登陆态(Session存储),加速一些热数据的查询(相比较mysql而言,速度有数量 ...

  9. zabbix-agent 启动不起来

    遇到一个问题  zabbix-agent 一直启动不起来 查看Zabbix Agent日志文件才究其原因. tail /var/log/zabbix/zabbix_agentd.logzabbix_a ...

  10. 17_8_9 Spring 注入

    1 Spring 的 Bean 的属性注入: 构造方法的方式注入属性: <!-- 第一种:构造方法的方式 --> <bean id="car" class=&qu ...