E. Connected Components?
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.

You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices X such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to X violates this rule.

Input

The first line contains two integers n and m (1 ≤ n ≤ 200000, ).

Then m lines follow, each containing a pair of integers x and y (1 ≤ x, y ≤ n, x ≠ y) denoting that there is no edge between x and y. Each pair is listed at most once; (x, y) and (y, x) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there exists an edge between those vertices.

Output

Firstly print k — the number of connected components in this graph.

Then print k integers — the sizes of components. You should output these integers in non-descending order.

Example
Input
5 5
1 2
3 4
3 2
4 2
2 5
Output
2
1 4

这题是求补图的联通块个数。用到了链表加bfs的强优化。
本人学习博客:http://blog.csdn.net/just_sort/article/details/54862268

最新文章

  1. ORACLE NUMBER类型Scale为0引发的问题
  2. 获取 view所在的VC
  3. mysql定时器Events
  4. iOS8中使用CoreLocation定位[转]
  5. window.onresize 多次触发的解决方法
  6. bzoj 1503: [NOI2004]郁闷的出纳员 Treap
  7. listview——显示窗体
  8. Storm源码分析--Nimbus-data
  9. ubuntu通过虚拟域名访问不了 502 / 网络错误
  10. 浏览器怎么解析一个hmtl文档
  11. 【日常学习】【线性DP】codevs1044 拦截导弹题解
  12. GIT工程迁移方法总结
  13. zeppelin中连接hive和impala
  14. Docker安装nexus
  15. 安装mysql8.0.12以及修改密码和Navicat的连接
  16. 洛谷P3376 【模板】网络最大流
  17. Jvm中时区设置方式
  18. Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))
  19. 枚举Enum转换为List,获取枚举的描述
  20. JUnit4 测试示例

热门文章

  1. 与图论的邂逅06:dfs找环
  2. 【JeecgBoot】关于 jeecg-boot 的项目理解、使用心得和改进建议
  3. 从零开始学spring源码之ioc预热:bean的拓展和beanProcessor注册
  4. C#高级编程第11版 - 第三章 索引
  5. Java面向对象(三)—— 继承
  6. Java面向对象(一)----初次见面
  7. REST 架构的替代方案 为什么说GraphQL是API的未来?
  8. linux 下解决mysql root 权限无法远程连接问题
  9. Java面试题及解析(判断题)
  10. DEDECMS:解决无法上传图片(在后台插入图片时提示类型不允许)