hdu-1232 unblocked Project

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1232

and check Set

#include <stdio.h> #include <iostream> #include <math.h> #include <stdlib.h> #include < ctype.h> #include <algorithm> #include <vector> #include <string.h> #include <queue># include<stack> #include <set> #include <map> #include <sstream> #include <time.h># include<utility> #include <malloc.h> #include <stdexcept>using namespace Std;int n,m;int p[10000];    int b [10000];int find (int x) {if (x==p[x]) return x; else return find (P[x]);}    int fa,fb;void un (int x,int y) {fa=find (p[x]);    Fb=find (P[y]);        if (FA!=FB) {if (FA&GT;FB) P[FA]=FB;    else P[FB]=FA;            }}int Main () {while (scanf ("%d%d", &n,&m)!=eof && N) {for (int i=1;i<=n;i++)        P[i]=i;                int sum=0;        int A, B;            for (int i=1;i<=m;i++) {scanf ("%d%d", &a,&b);        Un (a, b); } for (int i=1;i<=n;i++) {if (p[i]==i) sum++;    } printf ("%d\n", sum-1); } return 0;}


hdu-1232 unblocked Project

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.