題解參考自:https://blog.csdn.net/qq_24489717/article/details/51313618
Problem Description
You have won a collection of tickets on luxury cruisers. Each ticket can be used only once, but can be used in either direction between the 2 different cities printed on the ticket. Your prize gives you free airfare to any city to start your cruising, and free airfare back home from wherever you finish your cruising.
You love to sail and don't want to waste any of your free tickets. How many additional tickets would you have to buy so that your cruise can use all of your tickets?
Now giving the free tickets you have won. Please compute the smallest number of additional tickets that can be purchased to allow you to use all of your free tickets.
Input
There is one integer T (T≤100) in the first line of the input.
Then T cases, for any case, the first line contains 2 integers n, m (1≤n, m≤100,000). n indicates the identifier of the cities are between 1 and n, inclusive. m indicates the tickets you have won.
Then following m lines, each line contains two integers u and v (1≤u, v≤n), indicates the 2 cities printed on your tickets, respectively.
Output
Sample Input
Sample Output
Source
“高教社杯”第三屆福建省大學生程序設計競賽題解:這一題的難點在於判斷圖的每個聯通分塊裏有多少條路構成不了歐拉路,那麼需要根據歐拉路的性質可知,對於無向圖,構成歐拉路的奇數點的個數爲0或者爲2,那麼我們只要統計出這個聯通分塊的(奇數點的個數-2)就是多餘出來的那些點,那麼直接累加(奇數點的個數-2)/2即可,代碼裏有更詳細的說明。
這裏我們使用並查集判斷聯通塊即可
--------------------------------------------------------------------------------------------------------------------
自己查的資料:
歐拉路:如果從一個點出發,所有的邊經過一次,則稱爲歐拉道路,如果最後回到了起點,那麼成爲歐拉回路
參考自:https://baike.baidu.com/item/%E6%AC%A7%E6%8B%89%E5%9B%9E%E8%B7%AF/10036484?fr=aladdin
歐拉路專題資料:https://blog.csdn.net/devil2b/article/details/41413743