随笔分类 -  并查集

More is better
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>#define maxn 10000010 int father[maxn],d[maxn];int find(int x){ return x==father[x]?x:father[x]=find(father[x]);}void merge(int x,int y){ x=find(x),y=find(y); if(x!=y) father[x]=y; }int main( ){ int N,i,j,a,b,k,t=0; while(scanf(& 阅读全文

posted @ 2011-04-30 23:51 more think, more gains 阅读(183) 评论(0) 推荐(0)

how many tables
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>int father[1100];int find(int x){ return x==father[x]?x:father[x]=find(father[x]);}void merge(int x,int y){ x=find(x),y=find(y); if(x!=y) father[x]... 阅读全文

posted @ 2011-04-30 22:26 more think, more gains 阅读(152) 评论(0) 推荐(0)

hdu 1233
摘要:#include<stdio.h>#include<algorithm>using namespace std;int father[110],N,M;struct node{ int i,j,v;}T[5000];int cmp(node a,node b){ return a.v<b.v;}int find(int x){ return x==father[x]?x:father[x]=find(father[x]);}void merge(int x,int y){ x=find(x); y=find(y); if(x!=y) father[x]=y;}in 阅读全文

posted @ 2011-04-30 11:13 more think, more gains 阅读(174) 评论(0) 推荐(0)

畅通工程 hdu 1223
摘要:#include<stdio.h>int father[1100],N,M;int find(int x){ return x==father[x]?x:father[x]=find(father[x]);}void merge(int x,int y){ x=find(x); y=find(y); if(x!=y) father[x]=y;}int main( ){ while(scanf("%d%d",&N,&M),N) { int i,j,a,b,count=1; for(i=1;i<=N;i++) father[i]=i; for( 阅读全文

posted @ 2011-04-30 11:00 more think, more gains 阅读(264) 评论(0) 推荐(0)

畅通工程
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int i; int j; int v;}T[5000];int father[110],rank[110];int N,M,t;int cmp(node a,node b){ return a.v<b.v;}int find(int x){ return x==father[x]?x:father[x]=find(father[x] 阅读全文

posted @ 2011-04-30 10:32 more think, more gains 阅读(153) 评论(0) 推荐(0)

继续畅通工程
摘要:#include<stdio.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int i,j,v,u;}T[10100];int father[10100],N,M;int cmp(node a,node b){ return a.v<b.v;}int find(int x){ return x==fa... 阅读全文

posted @ 2011-04-30 09:34 more think, more gains 阅读(162) 评论(0) 推荐(0)

导航