IITKESO207PA6Q2 - Metro City
A country has n islands numbered 0 to n-1. Some of these islands are connected by bridges. You are given that all bridges are two-way. Moreover, the initial network is such that it is possible to go from any island to any other island (via bridges). However, the country could face trouble when the water level rises and islands are submerged. When an island is submerged, all bridges incident on that island are shutdown. We call an island z bad if submerging that bridge disconnects the country, i.e., there exist two islands x, y such that we cannot go from x to y if z is submerged (x, y are distinct from z). You are required to find all the bad islands in the city.
First line of input consists of 2 space separated integers n and m. n denotes the number of islands and m denotes the total number of bridges initially. m lines follow.
Each of the m lines denotes the two endpoints of a bi-directional bridge.
Output a list of the bad islands in sorted order.
Input: 5 5
1 4 Output: 2