CF920E.Connected Components?

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an undirected graph consisting of nn vertices and edges. Instead of giving you the edges that exist in the graph, we give you mm unordered pairs ( x,yx,y ) such that there is no edge between xx and yy , 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 XX 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 XX violates this rule.

输入格式

The first line contains two integers nn and mm ( 1<=n<=2000001<=n<=200000 , ).

Then mm lines follow, each containing a pair of integers xx and yy ( 1<=x,y<=n1<=x,y<=n , xyx≠y ) denoting that there is no edge between xx and yy . Each pair is listed at most once; ( x,yx,y ) and ( y,xy,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.

输出格式

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

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

输入输出样例

  • 输入#1

    5 5
    1 2
    3 4
    3 2
    4 2
    2 5
    

    输出#1

    2
    1 4 
首页