A8663 | Counter Attack
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has $n$ cities, numbered from $1$ to $n$ , and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we do not know whether is it a clever spy-proof strategy or just saving ink). In other words, if two cities are connected by a road on a flatland map, then there is in fact no road between them. The opposite situation is also true: if two cities are not connected by a road on a flatland map, then in fact, there is a road between them.
The berlanders got hold of a flatland map. Now Vasya the Corporal is commissioned by General Touristov to find all such groups of flatland cities, that in each group of cities you can get from any city to any other one, moving along the actual roads. Also the cities from different groups are unreachable from each other, moving along the actual roads. Indeed, destroying such groups one by one is much easier than surrounding all Flatland at once!
Help the corporal complete this task and finally become a sergeant! Don't forget that a flatland map shows a road between cities if and only if there is in fact no road between them.
Flatland has $n$ cities, numbered from $1$ to $n$ , and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we do not know whether is it a clever spy-proof strategy or just saving ink). In other words, if two cities are connected by a road on a flatland map, then there is in fact no road between them. The opposite situation is also true: if two cities are not connected by a road on a flatland map, then in fact, there is a road between them.
The berlanders got hold of a flatland map. Now Vasya the Corporal is commissioned by General Touristov to find all such groups of flatland cities, that in each group of cities you can get from any city to any other one, moving along the actual roads. Also the cities from different groups are unreachable from each other, moving along the actual roads. Indeed, destroying such groups one by one is much easier than surrounding all Flatland at once!
Help the corporal complete this task and finally become a sergeant! Don't forget that a flatland map shows a road between cities if and only if there is in fact no road between them.
输入格式
The first line contains two space-separated integers $n$ and $m$ $(1<=n<=5·10^{5},0<=m<=10^{6})$ — the number of cities and the number of roads marked on the flatland map, correspondingly.
Next $m$ lines contain descriptions of the cities on the map. The $i$ -th line contains two integers $a_{i}$ and $b_{i}$ $(1<=a_{i},b_{i}<=n,a_{i}≠b_{i})$ — the numbers of cities that are connected by the $i$ -th road on the flatland map.
It is guaranteed that each pair of cities occurs in the input no more than once.
Next $m$ lines contain descriptions of the cities on the map. The $i$ -th line contains two integers $a_{i}$ and $b_{i}$ $(1<=a_{i},b_{i}<=n,a_{i}≠b_{i})$ — the numbers of cities that are connected by the $i$ -th road on the flatland map.
It is guaranteed that each pair of cities occurs in the input no more than once.
输出格式
On the first line print number $k$ — the number of groups of cities in Flatland, such that in each group you can get from any city to any other one by flatland roads. At the same time, the cities from different groups should be unreachable by flatland roads.
On each of the following $k$ lines first print $t_{i}$ $(1<=t_{i}<=n)$ — the number of vertexes in the $i$ -th group. Then print space-separated numbers of cities in the $i$ -th group.
The order of printing groups and the order of printing numbers in the groups does not matter. The total sum $t_{i}$ for all $k$ groups must equal $n$ .
On each of the following $k$ lines first print $t_{i}$ $(1<=t_{i}<=n)$ — the number of vertexes in the $i$ -th group. Then print space-separated numbers of cities in the $i$ -th group.
The order of printing groups and the order of printing numbers in the groups does not matter. The total sum $t_{i}$ for all $k$ groups must equal $n$ .
输入输出样例
输入 #1
4 4 1 2 1 3 4 2 4 3
输出 #1
2 2 1 4 2 2 3
输入 #2
3 1 1 2
输出 #2
1 3 1 2 3
In the first sample there are roads only between pairs of cities 1-4 and 2-3.
In the second sample there is no road between cities 1 and 2, but still you can get from one city to the other one through city number 3.
In the second sample there is no road between cities 1 and 2, but still you can get from one city to the other one through city number 3.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted