Check the HDU 2120

Source: Internet
Author: User

Tag: and query set

In fact, it is to determine whether the newly added vertex is in the same set.

Code abuse me a thousand times, I am waiting for the first love of code

Ice_cream's world I Time Limit: 3000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 583 accepted submission (s): 333


Problem descriptionice_cream's world is a rich country, it has alias fertile lands. today, the queen of ice_cream wants award land to diligent acmers. so there are some watchtowers are set up, and wall between watchtowers be build, In order to partition the ice_cream's world. but how many acmers at most can be awarded by the Queen is a big problem. one wall-surrounded land must be given to only one acmer and no Wils are crossed, if you can help the Queen solve this problem, you will be get a land.
Inputin the case, first two integers n, m (n <= 1000, m <= 10000) is represent the number of watchtower and the number of wall. the Watchtower numbered from 0 to N-1. next following M lines, every line contain two integers A, B mean between A and B has a wall (A and B are distinct ). terminate by end of file.
Outputoutput the maximum number of acmers who will be awarded.
One answer one line.
Sample Input
 
8 100 11 21 32 43 40 55 66 73 64 7

Sample output
 
3
# Include <stdio. h> # include <stdlib. h> # include <malloc. h> # include <limits. h> # include <ctype. h> # include <string. h> # include <string> # include <queue> # include <algorithm> # include <iostream> # include <stack> # include <deque> # include <vector> # include <set> # include <map> using namespace STD; # define maxn 1000 + 10 # define maxn1 10000 + 10int father [maxn]; int A [maxn1]; int B [maxn1]; int find (INT X) {If (X! = Father [x]) {FATHER [x] = find (father [x]);} return father [X];} int main () {int n, m; int I; while (~ Scanf ("% d", & N, & M) {for (I = 0; I <maxn; I ++) {FATHER [I] = I ;} memset (A, 0, sizeof (a); memset (B, 0, sizeof (B); for (I = 0; I <m; I ++) {scanf ("% d", & A [I], & B [I]) ;}int sum = 0; for (I = 0; I <m; I ++) {int F1 = find (A [I]); int F2 = find (B [I]); If (F1! = F2) {If (F1 <F2) {FATHER [F2] = F1;} else {FATHER [F1] = F2 ;}} else {sum ++ ;}} printf ("% d \ n", sum);} return 0 ;}


Check the HDU 2120

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.