#C7188. Hiking Trails Cycle Counter

    ID: 51031 Type: Default 1000ms 256MiB

Hiking Trails Cycle Counter

Hiking Trails Cycle Counter

John is planning a hiking trip across a new national park filled with numerous trail junctions. As new trails are built between these junctions, cycles (or circuits) may be formed. Your task is to determine, after each newly added trail, the total number of cycles that have been created in the trail network.

The park has n junctions labeled from 1 to n. Trails are added one by one, each connecting two different junctions. Initially, the junctions are disconnected. When a new trail is added:

  • If the two junctions are not already connected, the trail connects two separate regions and no cycle is formed.
  • If the two junctions are already connected, adding this trail creates a new cycle. The number of cycles is incremented by one.

Since the number of cycles can be very large, output each value modulo \(10^9+7\).

Example: For n=4 and the trails sequence: (1,2), (2,3), (3,4), (4,1), (1,3), the answers after each addition are: [0, 0, 0, 1, 2].

inputFormat

The first line contains two space-separated integers: n (the number of junctions) and m (the number of trails).

The following m lines each contain two space-separated integers u and v representing a trail connecting junction u and junction v.

outputFormat

Output a single line containing m space-separated integers. The \(i^{th}\) integer represents the total number of cycles formed (modulo \(10^9+7\)) after adding the \(i^{th}\) trail.

## sample
4 5
1 2
2 3
3 4
4 1
1 3
0 0 0 1 2