CF190E.Counter Attack

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

贝兰德已成功击退了平面国的进攻,现在正准备发起反攻。

平面国有 nn 座城市,编号从 11 到 nn,其中某些城市对之间由双向道路连接。平面国的地图上,仅当两座城市之间实际上没有道路时,才在地图上画出一条连接它们的道路(我们尚不清楚这是精明的反间谍策略,还是仅仅为了节省墨水)。换言之:若地图上两座城市之间画有一条道路,则现实中这两座城市之间并无道路;反之亦然:若地图上两座城市之间没有画出道路,则现实中这两座城市之间确实存在道路。

贝兰德士兵获得了一张平面国地图。现在,图里斯托夫将军委派下士瓦夏完成一项任务:找出所有满足如下条件的城市集合——在每个集合内部,任意两座城市均可通过实际存在的道路相互到达;而不同集合之间的城市则无法通过实际存在的道路相互到达。事实上,逐个摧毁这些连通块,远比一次性包围整个平面国要容易得多!

请帮助这位下士圆满完成任务,从而最终晋升为中士!切记:平面国地图上画出道路,当且仅当现实中该对城市之间没有道路。

输入格式

The first line contains two space-separated integers n and m (1 ≤ n ≤ 5·105, 0 ≤ m ≤ 106) — 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.

第一行包含两个以空格分隔的整数 nn 和 mm(1 ≤ n ≤ 5⋅1051 ≤ n ≤ 5·10^5,0 ≤ m ≤ 1060 ≤ m ≤ 10^6),分别表示平地地图上的城市数量和道路数量。

接下来 mm 行描述地图上的道路。第 ii 行包含两个整数 aia_i 和 bib_i(1 ≤ ai, bi ≤ n1 ≤ a_i, b_i ≤ n,ai ≠ bia_i ≠ b_i),表示第 ii 条道路所连接的两座城市的编号。

保证输入中每对城市至多出现一次。

输出格式

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.

第一行输出一个整数 kk —— Flatland 中城市的连通分量个数,即每个连通分量内任意两个城市均可通过 Flatland 的道路相互到达;而不同连通分量中的城市之间则无法通过 Flatland 的道路相互到达。

接下来的 kk 行中,每行首先输出 tit_i(1≤ti≤n1 \le t_i \le n)—— 第 ii 个连通分量中的顶点(城市)数量,然后在同一行输出该连通分量中所有城市的编号(以空格分隔)。

各连通分量的输出顺序,以及每个连通分量内部城市编号的输出顺序均不重要。所有 kk 个连通分量的 tit_i 之和必须等于 nn。

输入输出样例

  • 输入#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.

在第一个样例中,仅有城市 1 与 4、城市 2 与 3 之间的道路。

在第二个样例中,城市 1 与 2 之间没有直接道路,但你仍可通过编号为 3 的城市从一个城市到达另一个城市。

输入解题思路,AI测评打分。不知道怎么写?

首页