Hdoj Ice_cream ' s World I 2120 "and check the set judgment into a ring"

Source: Internet
Author: User

Ice_cream ' s World I Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 848 Accepted Submission (s): 494


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
Sourcehdu 2007-10 Programming Contest_warmup
Recommend Whisky | We have carefully selected several similar problems for you:2122 2118 2119 2121 2117

Test instructions: Judging there are several rings

And check the set to judge the ring

Determine if the parent node is the same if there is a ring

#include <iostream> #include <stdio.h> #include <algorithm>using namespace std;int r[1010];int flag; int find_x (int x) {while (x!=r[x]) X=r[x];return x;} void Fun (int x,int y) {x=find_x (x); y=find_x (y); if (x!=y) {r[y]=x;} else flag++;} int main () {    int n,m;    while (scanf ("%d%d", &n,&m)!=eof) {for (int i=0;i<=n;i++) r[i]=i;flag=0;int a,b;for (int i=0;i<m;i++) { scanf ("%d%d", &a,&b); fun (b);} printf ("%d\n", flag);    }    return 0;}


Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.

Hdoj Ice_cream ' s World I 2120 "and check the set to determine the ring"

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.