文章分类 - 并查集
摘要:#include <stdio.h>#include <string.h>#define MAXN 100005int father[MAXN],de[MAXN];bool iscyle[MAXN];int find(int x){ int i,t; for(i=x;father[i]>=0;i=father[i]) ; while(x!=i) { t=father[...
阅读全文
摘要:判断环的个数#include <stdio.h>#include <string.h>#define MAXN 1003int father[MAXN];int find(int x){ int i,t; for(i=x; father[i]>=0; i=father[i]) ; while(x!=i) { t=father[x]; father[x]=i; x=t;...
阅读全文
摘要:#include <stdio.h>#include <string.h>#define MAXN 10000003int ans,father[MAXN];int find(int x){ int i,t; for(i=x; father[i]>0; i=father[i]) ; while(x!=i) { t=father[x]; father[x]=i; x=t...
阅读全文
摘要:#include <stdio.h>#include <string.h>#define MAXN 1003int father[MAXN];bool table[MAXN];int find(int x){ int i,t; for(i=x; father[i]>0; i=father[i]) ; while(x!=i) { t=father[x]; father[...
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#define MAXN 100005int father[MAXN];bool exist[MAXN];int find(int x){ int i,t; for(i=x; father[i]>0; i=father[i]) ; while(x...
阅读全文
摘要:tarjan 46MS:#include <stdio.h>#include <string.h>#include <vector>using namespace std;#define MAXN 10005vector<int> adjlist[MAXN];int bcnt,times,dfn[MAXN],low[MAXN],stk[MAXN],t...
阅读全文
摘要:#include stdio.h#include string.h#include stdlib.h#define MAXN 1005int father[MAXN];bool exist[MAXN];int find(int x){ int i,t; for(i=x; father[i]0; i=father[i]) ; while(x!=i) { t=father[x]; father[x]=...
阅读全文
摘要:http://acm.timus.ru/problem.aspx?space=1&num=1124题目大意是,有M种卡片,每种有N个,初始时放在M个盒子里,每个盒子里有N张,但是可能有某些卡片放错了位置,因此需要进行一些移动,最后使得每张卡片都放到它应该在的盒子(第1种卡片都放入盒子1,第2种卡片都放入盒子2……)。一次移动是指把一张卡片从当前手边的盒子里拿出放...
阅读全文
摘要:http://acm.nuaa.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1087思路:反过来做的题目,先将所有边和操作存起来,遇到'D'则标记;将未标记的边用并查集并起来;倒着一系列的操作,遇到'D'则合并,遇到'Q'则普通地查询并查集,将答案存起来。最后倒着答案输入,理解理解。。。#include <std...
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <math.h>#define MAXN 1005#define MAXQ 300005struct coor{ int x,y;};coor pos[MAXN];int father[MAXN],repaired[MAXQ];inline double dis(int ...
阅读全文
摘要:#include <stdio.h>#include <string.h>#define MAXN 30001int father[MAXN];inline int find(int x){ int i,t; for(i=x; father[i]>=0; i=father[i]) ; while(x!=i) { t=father[x]; father[x]=i; x=...
阅读全文
摘要:#include <stdio.h>#include <string.h>#define MAXN 50005int father[MAXN];inline int find(int x){ int i,t; for(i=x; father[i]>0; i=father[i]) ; while(x!=i) { t=father[x]; father[x]=i; x=t...
阅读全文
摘要://方法1,思路更清晰#include <stdio.h>#include <string.h>#define MAXN 100005int father[MAXN],diff[MAXN];int find(int x){ int i,t; for(i=x; father[i]>0; i=father[i]) ; while(x!=i) { t=father[x]; ...
阅读全文
摘要://方法1,思路更清晰#include <stdio.h>#include <string.h>#define MAXN 2005int father[MAXN],diff[MAXN];int find(int x){ int i,t; for(i=x; father[i]>0; i=father[i]) ; while(x!=i) { t=father[x]; fa...
阅读全文
摘要:#include <stdio.h>#define MAXN 30005int father[MAXN],before[MAXN],count[MAXN];int find(int x){ if(father[x]<0) return x; int f=find( father[x] ); before[x] += before[ father[x] ]; return fath...
阅读全文
浙公网安备 33010602011771号