#P3469. Impact of Blocking a Town

    ID: 16724 Type: Default 1000ms 256MiB

Impact of Blocking a Town

Impact of Blocking a Town

Byteotia has exactly \( n \) towns connected by bidirectional roads such that there exists a route between any two towns. Each town has exactly one citizen, and in the absence of obstacles, every citizen would visit every other citizen's hometown exactly once, leading to \( n(n-1) \) visits in total.

As a protest, programmers plan to block one town, making it inaccessible (you cannot enter, exit, or even pass through it). When a town \( X \) is blocked, the remaining \( n-1 \) towns become partitioned into one or more connected components (depending on whether \( X \) is an articulation point). A visit between two citizens in the same connected component can still occur (since a path exists that avoids \( X \)); however, visits between citizens in different components become impossible.

Your task is to determine, for each town \( X \), the total number of visits that can still take place if town \( X \) is blocked. Note that if a connected component has \( s \) towns, then the number of visits possible within that component is \( s(s-1) \) (each ordered pair of distinct towns in that component constitutes a valid visit).

inputFormat

The input is given on the standard input and has the following format:

  • The first line contains two integers \( n \) and \( m \), representing the number of towns and the number of bidirectional roads, respectively.
  • Each of the next \( m \) lines contains two integers \( u \) and \( v \) indicating that there is a road connecting towns \( u \) and \( v \).

It is guaranteed that the graph is connected and that there is at most one road between any two towns.

outputFormat

Output \( n \) lines. The \( i \)-th line should contain a single integer representing the total number of visits that can take place if town \( i \) is blocked.

sample

4 3
1 2
2 3
3 4
6

2 2 6

</p>