随笔分类 - 并查集
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 ...
阅读全文
摘要:#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...
阅读全文
摘要:#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",...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文
摘要:#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...
阅读全文
摘要://对数组排序后,对于边相同并且边的两端不在一个集合内的一定是等效边或者必加边,//第一数数,第二合并集合#include#include#define N 110000int pre[N];struct node {int x,y,w;}ma[N];int findd(int x) {if(x!=...
阅读全文
摘要:#include//从大到小不断枚举边直到找到s-t的路径,判断从s可以到t可以用并查集来判断#include//枚举最大的一条边肯定要找和他的值最接近的边,所以要排序#defineN5100#defineinf0x3fffffffstructnode{intu,v,speed;}map[N];in...
阅读全文
摘要:#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[...
阅读全文
摘要:http://www.cnblogs.com/newpanderking/archive/2012/10/18/2729566.html#include#include#include#includeusing namespace std;const int N=11000;vectorlink[N...
阅读全文
摘要:#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...
阅读全文
摘要: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...
阅读全文
摘要:#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...
阅读全文
摘要://不容易啊,终于自己a了一道这种类型的题//#include#includeusing namespace std;const int N=30010;struct node {int front,last,count;}pre[N];int find(int x) {//指向队尾if(x!=pr...
阅读全文
摘要:#include#includeusing namespace std;const int N=40010;int pre[N];//并查集int visit[N];//是否经过int ancestor[N];//祖先int dis[N];//储存距离int result[N];//储存结果stru...
阅读全文
摘要:#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 ...
阅读全文
摘要:#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...
阅读全文
摘要:不会写果断看答案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]...
阅读全文
摘要:#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...
阅读全文
1
浙公网安备 33010602011771号