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

模板 并查集

时间:2015-05-03 10:36:49      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:

【模板】并查集

 

 1 int find(int x)
 2 {
 3     int r = x;
 4     while(father[r]!=r)
 5     r = father[r];
 6     return r;
 7 }
 8 /*
 9 int find(int x)
10 {
11     if(father[x] == x)
12     return x;
13     else
14     return father[x] =find(father[x]);
15 }
16 */
17 
18 void join(int x,int j)
19 {
20     int fx = find(x),fy = find(y);
21     if(fx!=fy)
22     father[fx] = fy;
23 }
24 
25 void Union(int x,int y)
26 {
27     int rx,ry;
28     rx = find(x);
29     ry = find(y);
30     father[rx] = ry;
31 }

 

模板 并查集

标签:

原文地址:http://www.cnblogs.com/jeff-wgc/p/4473358.html

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