and check Set

Source: Internet
Author: User

And check set is a data structure, easy to find elements of the same feature, so we need to learn

And check set is a tree-type data structure, which is used to deal with the merging and querying problems of disjoint sets. Often used in the forest to express.                                      A set is a collection of elements that make up each element, that is, the collection of elements belonging to the same group in a certain order. -------from Wikipedia the following code:
Const intmaxn=10001;intFATHER[MAXN];voidDateins ()//initializing an array{     for(i=1; i<=n;i++) Father[i]=i;}int_findx (intX//find the number in which to assign the value{    if(father[x]!=x) father[x]=_find (father[x])returnfather[x];}voidDatecin () {
int m; scanf ("%d",&m); for(intI=1; i<=m;i++) {scanf ("%d%d",&a,&b); A=_find (a); b=_find (b); Father[a]=b; }}voidDatecal (intAintBB) {a=_find (a); b=_find (b); if(a==b) {printf ("yes\n"); } Else{printf ("no\n"); }}

The above is the contents of the set, in fact, is to set up an array to point to a value, and finally unify it to a point, thus unifying to a set, we can judge whether it is in this set.

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.