Codeforces Round 584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
D
Cow and Snacks
Codeforces
1700
原题
← CE1 →
翻译中…

The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!

翻译中…

There are $n$ snacks flavors, numbered with integers $1, 2, \ldots, n$. Bessie has $n$ snacks, one snack of each flavor. Every guest has exactly two favorite flavors. The procedure for eating snacks will go as follows:

翻译中…
  • First, Bessie will line up the guests in some way.
  • Then in this order, guests will approach the snacks one by one.
  • Each guest in their turn will eat all remaining snacks of their favorite flavor. In case no favorite flavors are present when a guest goes up, they become very sad.
翻译中…

Help Bessie to minimize the number of sad guests by lining the guests in an optimal way.

翻译中…

Input

翻译中…

The first line contains integers $n$ and $k$ ($2 \le n \le 10^5$, $1 \le k \le 10^5$), the number of snacks and the number of guests.

翻译中…

The $i$-th of the following $k$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \ne y_i$), favorite snack flavors of the $i$-th guest.

翻译中…

Output

翻译中…

Output one integer, the smallest possible number of sad guests.

翻译中…

Note

翻译中…

In the first example, Bessie can order the guests like this: $3, 1, 2, 4$. Guest $3$ goes first and eats snacks $1$ and $4$. Then the guest $1$ goes and eats the snack $2$ only, because the snack $1$ has already been eaten. Similarly, the guest $2$ goes up and eats the snack $3$ only. All the snacks are gone, so the guest $4$ will be sad.

翻译中…

In the second example, one optimal ordering is $2, 1, 3, 5, 4$. All the guests will be satisfied.

翻译中…

样例

Input #1
5 4
1 2
4 3
1 4
3 4
Output #1
1
InputCopy OutputCopy
Input #2
6 5
2 3
2 1
3 4
6 5
4 5
Output #2
0
InputCopy OutputCopy
标签
DFS 及类似
并查集
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。