Eight 2 Zero
Time limit1sMemory limit1024 MB
Given a connected graph with N nodes and N+1 links, find the fewest links to remove so that every remaining node lies on exactly one cycle.
- Level
Medium6 of 10
- Topics
- Graph, BFS, Implementation
- Solved
- No attempts yet
Problem
A network system consists of nodes and links. A link connects two different nodes in both directions. Two nodes connected by a link can communicate, and if can communicate with and can communicate with , then can communicate with too.
There is a network of nodes numbered from to and links. At most one link connects any two nodes, and any two nodes in the network can communicate.
You think the network is too complicated, so you decide to remove some links. Removing links may leave a node unable to communicate with any other node. Such a node is called an inactive node. A node that is not inactive is called an active node.
You consider a ring to be the simplest structure, so you want to build the network out of rings. A ring is a subnetwork in which any two nodes can communicate, and starting from any node and following links, you can return to the starting node. A ring must use at least one link, and it must not use the same link more than once. Here are examples of rings.

Here are examples of networks that are not rings. A network may contain a ring, but the whole network is not a ring, so keep that in mind.

Find the minimum number of links you must remove so that every active node belongs to exactly one ring.
Input
The first line contains the number of nodes .
From the second line through the -th line, the information about the links is given. Each line contains the numbers of the two nodes that the link connects, separated by a space.
Output
On the first line, print the minimum number of links that must be removed.