并查集是一种树型的数据结构,用于处理一些不交集的合并及查询问题。
给出一个有向图,经过并查集算法可以很快地判断任意连个点是否属于同一个集合。
#include<iostream>
#include<stdio.h>
#include<string.h>
#define MAXN 1000
using namespace std;
int root[MAXN]; //the root of a node
int layer[MAXN];
int n, m; //the number of node and edge
void init(){
for (int i =

并查集是一种高效处理不交集合并与查询的数据结构。本文介绍如何使用C++编写并查集算法模板,通过该模板可以快速判断有向图中任意两点是否属于同一集合。

3383

被折叠的 条评论
为什么被折叠?



