Under construction

Still being built. Things may change

Eight 2 Zero

Time limit1sMemory limit1024 MB

Summary
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 AA can communicate with BB and BB can communicate with CC, then AA can communicate with CC too.

There is a network of NN nodes numbered from 11 to NN and N+1N+1 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 NN. (4≤N≤300 000)(4\leq N \leq 300\,000)

From the second line through the (N+1)(N+1)-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.

Examples1

  1. Example 1

    Input
    8
    1 5
    7 4
    2 8
    3 1
    4 8
    6 2
    1 7
    8 5
    3 6
    
    Expected output
    2