#K10826. Corridor Removal in the Castle

    ID: 23333 Type: Default 1000ms 256MiB

Corridor Removal in the Castle

Corridor Removal in the Castle

In a medieval castle with \( n \) rooms and \( m \) corridors connecting them, it is critical to maintain overall connectivity. Each corridor connects two rooms, and the castle is said to be connected if there is a path between any pair of rooms.

Your task is to determine for each corridor whether it can be safely removed without disconnecting the castle. Formally, for each given corridor \( (u,v) \), remove it temporarily and check if the resulting graph remains connected. Output a \( 1 \) if the castle stays connected after removing the corridor, and \( 0 \) if it becomes disconnected.

Input constraints: The first input line contains two integers \( n \) and \( m \). Each of the next \( m \) lines contains two integers representing a corridor between rooms. You may assume the rooms are numbered from \( 1 \) to \( n \).

Note: If there are no corridors (i.e. \( m = 0 \)), output nothing.

inputFormat

The input is given via standard input. The first line contains two integers ( n ) and ( m ), representing the number of rooms and corridors respectively. Each of the following ( m ) lines contains two integers ( u ) and ( v ) indicating an undirected corridor between room ( u ) and room ( v ).

outputFormat

Print a single line to standard output containing ( m ) integers separated by a space. For each corridor (in the same order as the input), print ( 1 ) if it can be removed without disconnecting the castle; otherwise, print ( 0 ).## sample

4 4
1 2
2 3
3 4
4 1
1 1 1 1