HDU 2120 ice_cream's world I (query set)

Source: Internet
Author: User

Address: HDU 2120

Although this question does not contain many words, it cannot be understood .. It means to find the maximum number of areas surrounded by walls. This is obviously the number of rings. Then, use and query the set to find the number of rings.

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int bin[2000];int find1(int x){    return bin[x]==x?x:bin[x]=find1(bin[x]);}int main(){    int n, m, ans, a, b, f1, f2, i;    while(scanf("%d%d",&n,&m)!=EOF)    {        ans=0;        for(i=0;i<n;i++)            bin[i]=i;        while(m--)        {            scanf("%d%d",&a,&b);            f1=find1(bin[a]);            f2=find1(bin[b]);            if(f1==f2)                ans++;            else                bin[f2]=f1;        }        printf("%d\n",ans);    }    return 0;}


HDU 2120 ice_cream's world I (query set)

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.