Hdu 2120 Ice_cream ' s World I

Source: Internet
Author: User

Topic Connection

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

Ice_cream ' s World idescription

Ice_cream ' s world is a rich country, it has 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.

Input

In the case, first and integers N, M (n<=1000, m<=10000) is represent the number of watchtower and the number of the Wal L. 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.

Output

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

Sample Input

8 10
0 1
1 2
1 3
2 4
3 4
0 5
5 6
6 7
3 6
4 7

Sample Output

3

Use and check the number of statistical rings.

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < cstdio> #include <vector> #include <map>using std::map;using std::min;using std::find;using std::p air; Using std::vector;using std::multimap; #define PB (E) push_back (e) #define SZ (c) (int) (c). Size () #define MP (A, b) make_pair (A, B) #define ALL (c) (c). Begin (), (c). End () #define ITER (c) __typeof ((c). Begin ()) #define CLS (arr, Val) memset (arr, Val, si Zeof (arr)) #define Cpresent (C, E) (Find (All (c), (e))! = (c). End ()) #define REP (i, n) for (int i = 0; i < (int) n; i++) #defi NE tr (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) const int N = 1010;const int INF = 0x3f3f3f3f;struct Uinonfin    d {int ans, par[n], rank[n];        inline void init (int n) {ans = 0;            Rep (i, n + 1) {par[i] = i;        Rank[i] = 0;        }} inline int find (int x) {while (x = Par[x]) {x = par[x] = par[par[x]];    } return x; } inlinevoid unite (int x, int y) {x = find (x), y = find (y);        if (x = = y) {ans++; return;}        if (Rank[x] < Rank[y]) {par[x] = y;            } else {par[y] = x;        RANK[X] + = rank[x] = = Rank[y];        }} inline void solve (int n, int m) {init (n);        int x, y;            while (m--) {scanf ("%d%d", &x, &y);        Unite (x, y);    } printf ("%d\n", ans);    }}go;int Main () {#ifdef LOCAL freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w+", stdout); #endif int n, m;    while (~SCANF ("%d%d", &n, &m)) {go.solve (n, m); } return 0;}

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.