Friend Groups
View as PDFPam is intruiged by the friend groups at her school. At the beginning of the school year, there are lone students, none of which know each other. A "join" happens when either
- 2 different lone students or
- 2 different friend groups or
- a single lone person and a friend group join together to form a single friend group.
If such joins occur throughout the school year, how many distinct friend groups will exist at the end of the school year? (Note that a lone person is also considered as a friend group).
Constraints
.
Input Specification
Two space-separated integers on one line: (the initial number of students) and
(the number of joins that occur throughout the year).
Output Specification
One integer: the number of distinct friend groups at the end of the year.
Sample Input
3 2
Output for Sample Input
1
Explanation for Sample Case
A possible sequence of events is:
Initially, everyone is a lone student:

Person joins with Person
:

Lastly, the [,
] friend-group joins with Person
:

Since all three of them are in the same friend group, there is friend group that remains.
Comments