欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1209D.Cow and Snacks
Cow and Snacks
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 snacks flavors, numbered with integers . Bessie has 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 and (, ), the number of snacks and the number of guests.
The -th of the following lines contains two integers and (, ), favorite snack flavors of the -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: . Guest goes first and eats snacks and . Then the guest goes and eats the snack only, because the snack has already been eaten. Similarly, the guest goes up and eats the snack only. All the snacks are gone, so the guest will be sad.
In the second example, one optimal ordering is . All the guests will be satisfied.
Samples
5 4
1 2
4 3
1 4
3 4
1
6 5
2 3
2 1
3 4
6 5
4 5
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |