随笔分类 -  并查集

1
摘要:/*只需判断等效边和必选边的个数和n-1的关系即可*/#include#include#define N 110struct node { int u,v,w;}f[N*N*2];int cmp(const void *a,const void*b) {return (*(struct node ... 阅读全文
posted @ 2014-08-14 20:31 HYDhyd 阅读(144) 评论(0) 推荐(0)
摘要:#include#define N 1100000struct node {int x,y;}f[N],pre[N];int find(int x) {if(x!=pre[x].x) { int h=pre[x].x; pre[x].x=find(h); pre[x].y=(pr... 阅读全文
posted @ 2014-06-29 19:39 HYDhyd 阅读(132) 评论(0) 推荐(0)
摘要:#include#define N 31000int pre[N];int find(int x) {if(x!=pre[x]) pre[x]=find(pre[x]);return pre[x];}int main() { int n,m,i,k,s,t; while(scanf("%d%d",... 阅读全文
posted @ 2014-06-27 17:10 HYDhyd 阅读(109) 评论(0) 推荐(0)
摘要:#include#include#define inf 0x3fffffff#define N 600struct node {int x,y,w;}ma[N*N];int cmp(const void *a,const void *b) {return (*(struct node *)a).w... 阅读全文
posted @ 2014-05-20 19:55 HYDhyd 阅读(147) 评论(0) 推荐(0)
摘要:#include#include#include#include#define N 700#define NN 2000010int prime[NN];int a[N];struct node {int x,y,w;}ma[N*N];void ispri() { int i,j; memset(p... 阅读全文
posted @ 2014-05-20 10:07 HYDhyd 阅读(212) 评论(0) 推荐(0)
摘要:#include#include#define N 1100struct node {int u,v,w;}bian[110000];int pre[N];int cmp(const void *a,const void *b) {return (*(struct node *)b).w-(*(st... 阅读全文
posted @ 2014-05-11 09:42 HYDhyd 阅读(121) 评论(0) 推荐(0)
摘要:#include#include#define N 300int pre[N];int find(int u) {if(u!=pre[u]) pre[u]=find(pre[u]);return pre[u];}struct node {int u,v,speed;}ma[1100];int cm... 阅读全文
posted @ 2014-05-04 23:34 HYDhyd 阅读(144) 评论(0) 推荐(0)
摘要://对数组排序后,对于边相同并且边的两端不在一个集合内的一定是等效边或者必加边,//第一数数,第二合并集合#include#include#define N 110000int pre[N];struct node {int x,y,w;}ma[N];int findd(int x) {if(x!=... 阅读全文
posted @ 2014-05-04 09:18 HYDhyd 阅读(159) 评论(0) 推荐(0)
摘要:#include//从大到小不断枚举边直到找到s-t的路径,判断从s可以到t可以用并查集来判断#include//枚举最大的一条边肯定要找和他的值最接近的边,所以要排序#defineN5100#defineinf0x3fffffffstructnode{intu,v,speed;}map[N];in... 阅读全文
posted @ 2014-04-29 15:58 HYDhyd 阅读(136) 评论(0) 推荐(0)
摘要:#include#include#define N 110000struct node { int father,count;}pre[N];int find(int x) {if(x==pre[x].father) {pre[x].count=0;return x;} int h=pre[... 阅读全文
posted @ 2014-03-08 17:01 HYDhyd 阅读(88) 评论(0) 推荐(0)
摘要:http://www.cnblogs.com/newpanderking/archive/2012/10/18/2729566.html#include#include#include#includeusing namespace std;const int N=11000;vectorlink[N... 阅读全文
posted @ 2013-12-03 17:06 HYDhyd 阅读(154) 评论(0) 推荐(0)
摘要:#include#include#define N 200100struct node {int x,count;}pre[N];int find(int n) {if(n!=pre[n].x) {int h=pre[n].x;pre[n].x=find(pre[n].x);pre[n].count... 阅读全文
posted @ 2013-12-01 18:12 HYDhyd 阅读(104) 评论(0) 推荐(0)
摘要:http://blog.sina.com.cn/s/blog_803d08c00100y2yy.html#include#include#includeusing namespace std;const int N =10010;struct node {int count,x;}pre[N];in... 阅读全文
posted @ 2013-12-01 17:33 HYDhyd 阅读(149) 评论(0) 推荐(0)
摘要:#include#include#include#define N 10010#define inf 999999999int pre[N];struct node {int x,deadline;}map[N];int cmp(const void *a,const void *b) {retur... 阅读全文
posted @ 2013-11-27 21:41 HYDhyd 阅读(102) 评论(0) 推荐(0)
摘要://不容易啊,终于自己a了一道这种类型的题//#include#includeusing namespace std;const int N=30010;struct node {int front,last,count;}pre[N];int find(int x) {//指向队尾if(x!=pr... 阅读全文
posted @ 2013-11-27 19:16 HYDhyd 阅读(109) 评论(0) 推荐(0)
摘要:#include#includeusing namespace std;const int N=40010;int pre[N];//并查集int visit[N];//是否经过int ancestor[N];//祖先int dis[N];//储存距离int result[N];//储存结果stru... 阅读全文
posted @ 2013-11-26 22:58 HYDhyd 阅读(107) 评论(0) 推荐(0)
摘要:#include//典型题#include#define N 40010struct node {int x,y,z;}pre[N];struct fff{int a,b,dis;char s[2];}map[N];//储存int find(int x) {if(x!=pre[x].z) {int ... 阅读全文
posted @ 2013-11-25 16:09 HYDhyd 阅读(190) 评论(0) 推荐(0)
摘要:#include#include#define N 100010int father[N],link[N];int find(int x) {if(x!=father[x]) {int h=father[x];father[x]=find(father[x]);link[x]=(link[x]+li... 阅读全文
posted @ 2013-11-24 22:27 HYDhyd 阅读(129) 评论(0) 推荐(0)
摘要:不会写果断看答案http://cavenkaka.iteye.com/blog/1489588#include#include#define N 50010int father[N],link[N];int find(int x) {if(x!=father[x]) {int h=father[x]... 阅读全文
posted @ 2013-11-24 18:20 HYDhyd 阅读(106) 评论(0) 推荐(0)
摘要:#include#include#include#define N 1100struct node { int x,y;}map[N];int s[N];int pre[N];int find(int n) { if(n!=pre[n]) pre[n]=find(pre[n]); return p... 阅读全文
posted @ 2013-11-18 13:01 HYDhyd 阅读(104) 评论(0) 推荐(0)

1