并查集C++实现

#include 

using namespace std;
class UF    {
	//cnt is the number of disjoint sets.
	//id is an array that records distinct identity of each set,when two sets are merged ,their id will be same.
	//sz is an array that records the child number of each set including the set self.
	int *id, cnt, *sz;
public:
	// Create an empty union find data structure with N isolated sets.
	UF(int N)   {
		cnt = N;
		id = new int[N];
		sz = new int[N];
		for (int i = 0; i

转载于:https://www.cnblogs.com/muyangshaonian/p/9650520.html

你可能感兴趣的:(c/c++)