摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=1829并查集,二分图识别如果A喜欢B,不能直接判断A,B的性别,但是可以知道,A喜欢的人和B是同性的(一个集合)。不直接合并A,B所在集合,而间接合并A喜欢的人所在集合 与 B所在集合,使问题得到简化。建立一个like数组,储存A喜欢的一个人为like[A](任意一个都可以),1.初始化:开始让每个人喜欢自己,like[i] = i;在执行合并操作(3)之前,如果A,B双方中还有喜欢自己的,则调整为喜欢对方,like[A] = B, like[B] = A;2.查询操作:如果A和B在一个集合中,则AB属于同性 阅读全文
posted @ 2013-01-15 15:28
Yuan1991
阅读(166)
评论(0)
推荐(0)
摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=1856并查集,集合计数多加一个sum数组,统计集合元素个数,初始化为1 1 #include <stdio.h> 2 #define N 10001000 3 4 int n, f[N], sum[N], max = 1;//f-->father 5 6 int find(int x) 7 { 8 return x-f[x]? f[x]=find(f[x]): x; 9 }10 11 void merge(int x, int y)12 {13 int r1, r2;//r-->roo 阅读全文
posted @ 2013-01-15 14:02
Yuan1991
阅读(162)
评论(0)
推荐(0)

浙公网安备 33010602011771号