#C6845. Isolated Networks

    ID: 50650 Type: Default 1000ms 256MiB

Isolated Networks

Isolated Networks

You are given n computers labeled from 1 to n. Initially, each computer is isolated. Then, a sequence of m cables is added, where each cable connects two computers.

After each cable addition, two computers (or networks) may become connected, reducing the total number of isolated networks. Your task is to output the number of isolated networks after each cable addition.

Two computers are in the same network if they are connected directly or through a series of connections. Formally, if we denote the initial number of isolated networks by \(n\), and after adding each cable the number of connected components becomes \(c_i\), then you need to output the sequence \(\{c_1, c_2, \dots, c_m\}\).

inputFormat

The input is given from standard input (stdin) with the following format:

n
m
u1 v1
u2 v2
...
um vm

Where:

  • n is the number of computers.
  • m is the number of cables to be added.
  • Each of the next m lines contains two integers u and v representing a cable connecting computer u and computer v.

outputFormat

Output to standard output (stdout) a single line containing m integers separated by spaces. The i-th integer represents the number of isolated networks after the i-th cable addition.

## sample
4
3
1 2
2 3
1 3
3 2 2

</p>