Road Construction
InterviewTime limit1sMemory limit128 MB
Given a connected undirected graph, add the fewest edges so that deleting any single edge still leaves the graph connected.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Greedy, Implementation
- Solved
- No attempts yet
Problem
It's almost summer, which means it's almost time for summer road construction! This year, the people in charge of the roads on the tropical island paradise of Remote Island want to repair and upgrade the various roads that lead between the tourist attractions on the island.
The roads themselves are rather interesting. Because of the island's unusual customs, the roads never meet at intersections; instead they pass over or under one another using bridges and tunnels. In this way each road runs directly between two specific tourist attractions, so that tourists never become hopelessly lost.
Unfortunately, given the nature of the repairs and upgrades, whenever the construction company works on a particular road, that road is unusable in both directions. This can be a problem if it makes it impossible to travel between two attractions, even though the company works on only one road at a time.
To prevent this, the road department has decided that new roads must be built so that, in the final configuration, if any single road is under construction it is still possible to travel between any two attractions using the remaining roads. Your task is to find the minimum number of new roads that must be built.
Input
The first line contains two positive integers and separated by a space, where is the number of tourist attractions on the island and is the number of roads. The attractions are labelled from to .
Each of the next lines contains two integers and separated by a space, indicating that a road connects the attractions labelled and . Each road may be travelled in either direction, and any pair of attractions is directly connected by at most one road. You are guaranteed that, in the current configuration, it is possible to travel between any two attractions.
Output
Output a single line containing one integer: the minimum number of roads that must be added.