CF1209D.Cow and Snacks

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn snacks flavors, numbered with integers 1,2,…,n1, 2, \ldots, n. Bessie has nn 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.

传奇农夫约翰正在举办一场盛大的派对,来自世界各地的动物们都聚集在他的家中。客人们饿了,于是他命令他的奶牛贝茜把零食端出来!哞!

共有 nn 种零食口味,编号为整数 1,2,…,n1, 2, \ldots, n。贝茜有 nn 份零食,每种口味各一份。每位客人恰好有两种最喜爱的口味。吃零食的过程如下:

  • 首先,贝茜以某种顺序将客人排成一列;
  • 然后,客人按此顺序依次上前取食;
  • 每位客人轮到自己时,会吃掉所有剩余的、属于其任一喜爱口味的零食。若某位客人上前时,其两种喜爱口味的零食均已无剩余,则该客人会感到非常伤心。

请帮助贝茜通过合理安排客人顺序,使得伤心的客人数量最少。

输入格式

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

The ii-th of the following kk lines contains two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n, xi≠yix_i \ne y_i), favorite snack flavors of the ii-th guest.

第一行包含两个整数 nn 和 kk(2≤n≤1052 \le n \le 10^5,1≤k≤1051 \le k \le 10^5),分别表示零食的种类数和客人的数量。

接下来的 kk 行中,第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤n1 \le x_i, y_i \le n,xi≠yix_i \ne y_i),表示第 ii 位客人最喜欢的两种零食口味。

输出格式

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

输出一个整数,即不开心的宾客的最少可能数量。

输入输出样例

  • 输入#1

    5 4
    1 2
    4 3
    1 4
    3 4

    输出#1

    1
  • 输入#2

    6 5
    2 3
    2 1
    3 4
    6 5
    4 5

    输出#2

    0

说明/提示

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

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

在第一个例子中,贝茜可以按如下顺序安排客人:3,1,2,43, 1, 2, 4。客人 33 首先入场,吃掉了零食 11 和 44;接着客人 11 入场,仅吃掉了零食 22(因为零食 11 已被吃掉);类似地,客人 22 入场,仅吃掉了零食 33。此时所有零食均已耗尽,因此客人 44 将感到难过。

在第二个例子中,一种最优的安排顺序是 2,1,3,5,42, 1, 3, 5, 4,此时所有客人都将得到满足。

输入解题思路,AI测评打分。不知道怎么写?

首页