Hdu2120ice_cream ' s World I (base and check set)

Source: Internet
Author: User

Ice_cream ' s World ITime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 698 Accepted Submission (s): 398


Problem Descriptionice_cream ' s world is a rich country, it had many fertile lands. Today, the Queen of Ice_cream wants award land to diligent acmers. So there is some watchtowers is set up, and wall between watchtowers is build, in order to partition the Ice_cream ' s WOR Ld. But what many acmers at most can be awarded by the Queen is a big problem. One wall-surrounded land must is given to only one acmer and no walls is crossed if you can help the Queen solve this PR Oblem, you'll be get-a land.
Inputin the case, first-integers N, M (n<=1000, m<=10000) is represent the number of watchtower and the number O F Wall. The watchtower numbered from 0 to N-1. Next following M lines, every line contain, integers a, b mean between A and b have A wall (A and B are distinct). Terminate by end of file.
Outputoutput the maximum number of acmers who'll be awarded.
One answer one line.
Sample Input
8 100 11 21 32 43 40 55 66 73 64 7

Sample Output
3

Authorwiskey Test Instructions: There are several rings in the picture.
#include <stdio.h>const int N = 1015;int fath[n],n;void init () {for    (int i =0;i<=n;i++)        fath[i]=i;} int Findfath (int x) {    if (x==fath[x])        return fath[x];    Fath[x]=findfath (Fath[x]);    return fath[x];} int setfath (int x,int y) {    x=findfath (x);    Y=findfath (y);    if (x==y)        return 1;    Fath[x]= y;    return 0;} int main () {    int x,y,m,ans;    while (scanf ("%d%d", &n,&m) >0)    {        init ();        ans=0;        while (m--)        {            scanf ("%d%d", &x,&y);            Ans+=setfath (x, y);        }        printf ("%d\n", ans);}    }


Hdu2120ice_cream ' s World I (base and check 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.