Winter training disjoint-set Starter Edition

#include <cstdio>
#include <CString>
#include <the iostream>
the using namespace STD;
const int MAXN = 105;

int FA [MAXN], height [MAXN];
int Find (int X) {
    return FA [X] == FA X [X]:? (FA [X] = Find (FA [X]));
}

/ * void the Merge (A int, int B) {
    FA [Find (A)] = Find (B); // low version Merge only the former to the latter may be merged to increase the depth
} * /

void Merge (A int, int B) {
    int RX = Find (A), Ry = Find (B);
    IF (height [RX] <height [Ry]) FA [rx] = Ry;
    the else FA [Ry] = rx;
    IF (height [rx] == height [Ry] && rx = Ry) height [rx] ++;! // the rx father set ry, that is to merge rx ry, depth plus 1
} // sophisticated version (in fact, almost less, because the path compression has to be shared equally single-step complexity of O (1) a), the main sophisticated in it as much as possible the depth of the tree so small

int main () {
    int n-;
    Scanf ( "% D", & n-);
    for (int i = 1; i <= n; ++ i) fa [i] = i; // initialize each parent node is its own node
    // what what is a pile and then, added to find what;
    return 0; // remember to add Yo
}
// this simple batch of simple path compression hit finished

Guess you like

Origin www.cnblogs.com/2004-08-20/p/12302555.html