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