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)