aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/dsa/DisjointSet.h
blob: 1ea6d97eb340a0b9b35dd9d6cd316f276f16f826 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef   DisjointSet_H__
#define   DisjointSet_H__

#include <vector>
#include <cstdlib>

namespace meow{
  class DisjointSet{
    private:
      size_t              n;
      std::vector<size_t> father;
      std::vector<size_t> depth;
      //
      size_t _root(size_t now);
      size_t _merge(size_t a, size_t b);
    public:
      DisjointSet();
      DisjointSet(size_t _n);
      DisjointSet(DisjointSet const& dsj);
      //
      size_t root (size_t a ) const;
      size_t size (         ) const;
      //
      void   reset(size_t _n         );
      size_t merge(size_t a, size_t b);
  };
}

#include "DisjointSet.hpp"


#endif // DisjointSet_H__