随笔分类 - 并查集
hdu 1598 find the most comfortable road
摘要:贪心+并查集fighting~~~~~!! 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 #define maxn 300 7 #define INF 0x3fffffff 8 int par[maxn]; ...
阅读全文
poj 1611 The Suspects
摘要:并查集 简单题 1 #include 2 #include 3 int par[1000]; 4 int Find(int x) 5 { 6 while(par[x] >= 0) 7 x = par[x]; 8 return x; 9 }10 void Merge(i...
阅读全文
hdu 1856 More is better
摘要:并查集 简单题 1 #include 2 #include 3 #include 4 #define N 10000005 5 using namespace std; 6 int par[N]; 7 int M[N]; 8 int Find(int x) 9 {10 if(par[x...
阅读全文
hdu 1232
摘要:并查集 入门题 1 #include 2 #include 3 int par[1000]; 4 int Find(int x) 5 { 6 while(par[x] > 0) 7 x = par[x]; 8 return x; 9 }10 void Merge(in...
阅读全文
ZOJ 1789 The Suspects
摘要:与2833差不多基本上只是merge函数那里的优先做父亲的条件改一下便可提高效率... 1 //The Suspects 2 #include 3 #include 4 int parent[30001]; 5 int find(int i) 6 { 7 while(parent[i] >=...
阅读全文
ZOJ 2833 Friendship
摘要:第一次敲并查集... 1 #include 2 #include 3 int parent[100002];//注意下标值,不然交了会segmentation fault 4 int find(int i) 5 { 6 while(parent[i] >= 0) 7 i = ...
阅读全文
浙公网安备 33010602011771号