Hdu 2120 Ice_cream ' s World I

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): 483 Accepted Submission (s): 262


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 is distinct). Terminate by end of file.

Outputoutput the maximum number of acmers who'll be awarded.
One answer one line.

Sample INPUT8 100 11 21 32 43 40 55 66 73 64 7

Sample OUTPUT3

Authorwiskey

Sourcehdu 2007-10 Programming Contest_warmup

Recommend Whisky |  We have carefully selected several similar problems for you:2118 2126 2129 2133 2925 The problem is an application of the set Judgment ring number. First of all, say test instructions, at the beginning to do this problem test instructions looked at a long time only to find that they understand the wrong.  = =: Abstract The topic after the meaning is probably said that there are n points at the beginning, respectively numbered 0~n-1.  And then I'll give you the M-message format for a B, meaning there's an edge connecting point A to point B, and finally asking how many areas (that is, how many rings) you will have when you connect the n dots with this m-line. So, if you can fully understand the words of test instructions, this question should be considered and check the set of the more naked problem. Now let's talk about why and check the collection can be awarded the ring. Start with the Kruskal algorithm; if you learn Kruskal, you should know it. The process of generating the smallest spanning tree: Each time you select two collections that belong to the same collection, and then merge them.  This process is repeated until all points are merged together, and a tree is obtained.  note! This generates a "tree", it is not any ring, in the Kruskal algorithm to use and check set to determine whether the two sets of two sets are the same,if they belong to the same set and merge them, they form a ring. So, in this case, using the M-bar information to merge the points constantly, determine whether the two points belong to a set, if not, then merge; otherwise, ring number plus one.
AC Code:
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <cstdlib>7#include <cctype>8#include <queue>9#include <stack>Ten#include <map> One#include <vector> A#include <Set> -#include <utility> -typedefLong Longll; the Const intinf=0x3f3f3f3f; - using namespacestd; -  - inta[ the],n,m; + voidinit ()//Initialize - { +      for(intI=0; i<=n; i++) Aa[i]=i; at } - // - intFatherintv)//Find Father node - { -     if(A[V]==V)returnv; -     returna[v]=father (A[v]); in } - voidUniteintUintv)//merge to { +     intTu=father (u), tv=father (v); -     if(TV!=TU) a[tv]=tu; the     // * } $ intMain ()Panax Notoginseng { -     //freopen ("Input.txt", "R", stdin); the     intu,v; +      while(SCANF ("%d%d", &n,&m)! =EOF) A     { the init (); +         intans=0; -          while(m--) $         { $scanf"%d%d",&u,&v); -             if(father (u) = =father (v)) -ans++; the             Else - Unite (U,V);Wuyi         } the         // -printf"%d\n", ans); Wu     } -     return 0; About}

Hdu 2120 Ice_cream ' s World I

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.