并查集
别哔哔好伐
安静的coder
展开
-
并查集 poj1611 The Suspects
#include #include using namespace std; int root[30001]; int find_(int x) { int r=x,temp; while(root[x]!=x) x=root[x]; while(r!=x){ // 路劲压缩 temp=root[r]; root[原创 2014-11-01 18:43:53 · 448 阅读 · 0 评论 -
UVA 10608 Friends 并查集
并查集水题 有n个人,m队朋友,朋友的朋友,也是朋友,A与B是朋友,B与C是朋友,那么A与C也是朋友,即A,B,C在同一个并查集里,合并即可; 最后会有几个“朋友圈子”,求最大的朋友圈的人数。 #include #include #include #include using namespace std; int r[30005]; int x[30010]; int init(int n原创 2014-11-14 22:21:52 · 747 阅读 · 0 评论