码迷,mamicode.com
首页 > 其他好文 > 详细

并查集模板!

时间:2014-10-10 22:28:24      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstdio>
 4 #include <cstring>
 5 #define N 30
 6 using namespace std;
 7 
 8 int ufs[N];
 9 
10 int Find(int x)
11 {
12     if(x==ufs[x]) return x;
13     ufs[x]=Find(ufs[x]);
14     return ufs[x];
15 }
16 
17 void Merge(int x,int y)
18 {
19    ufs[Find(x)]=Find(y);
20 }
21 
22 int main()
23 {
24     for(int i=0;i<N;i++) ufs[i]=i;
25 }
View Code

 

并查集模板!

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/M-D-LUFFI/p/4017720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!