A11477 | Connected Components?
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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.
Then print $k$ 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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted