Constellations
Limits: 2 sec., 256 MiB
One winter evening Marichka and Zenyk laid on the snow and watched stars. There were a lot of them and they were very beautiful. Marichka and Zenyk numbered all the stars they saw on the sky from \(1\) to \(N\).
Our sweethearts decided to have some fun (what else should they do under the starry sky?). Marichka said a star’s number and Zenyk said another star’s number. Then they connected these stars with imaginary lines. They spent almost half night doing this, so they got lots of connected stars groups. Zenyk and Marichka called these groups constellations. Some stars were left lonely (not connected to other stars) but our heroes decided them to be constellations as well.
In order not to waste the night they decided to calculate how many connections does every constellation have. But they need to do it very quickly because it’s winter and they can get cold while lying on the snow.
Two stars are considered to belong to the same constellation if they are connected directly or through other stars.
Input
The first row contains two integers separated by a space character: \(N\) and \(M\) — the number of stars on the sky and the number of imaginary connections between the stars. Next \(M\) rows contain two integers each: \(A_i\), \(B_i\) — the star number that Marichka said and star number, Zenyk said respectively.
Output
The first row should contain integer \(K\) — the total amount of constellations on the sky. Next \(K\) rows should contain the number of connections of each constellation it the non-descending order.
Constraints
\(1 \le N, M \le 10000 (10^4)\),
\(1 \le Ai, Bi \le N\),
\(A \ne B\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 6 5 1 2 2 3 4 5 2 1 3 1 | 3 0 1 4 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|