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 A snacks flavors, numbered with integers 1,2,…,A. Bessie has A snacks, one snack of each flavor. Every guest has exactly two favorite flavors. The procedure for eating snacks will go as follows:
Help Bessie to minimize the number of sad guests by lining the guests in an optimal way.
First argument of input contains a single integer A Second argument of input contains a 2 x M integer matrix B denoting favorite flavor of each guest.
return a single integer denoting the smallest possible number of sad guests.
2 <= N <= 100000 1 <= M <= 100000 1 <= B[i] , B[i] <= N B[i] != B[i]
Input 1: A = 5 , B = [[1, 2], [4, 3], [1, 4], [3, 4]] Output 1: 1 Explanation: 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. Input 2: A = 6 , B =[[2, 3], [2, 1], [3, 4], [6, 5], [4, 5]] Output 2: 0
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.