并查集 带压缩路径的版本
摘要:
#include <iostream>using namespace std;typedef struct{int a,b;}road;const int MAX=5001;int N,M,K;int father[MAX];int rank[MAX];road rd[500000];void make_set(){int i;for(i=1;i<=N;i++){father[i]=i;rank[i]=0;}}int find_set(int x){if(x!=father[x])father[x]=find_set(father[x]);return father[x];} 阅读全文
posted @ 2011-09-26 16:12 Knuth_档案 阅读(287) 评论(0) 推荐(0) 编辑