摘要:
题意:基本的lca问题分析:lca的离线算法为tarjan,tarjan算法的流程如下。dfs遍历树,节点a在遍历完成之后退回到a在树中的父亲节点,然后a在并查集中的father指针会指向这个父亲节点。也就是说一个节点,所有以它的被遍历过的直接子节点为根的子树中的点都会在并查集中被合并到这个点,并以它作为代表元。最开始每个点自己一个集合,每次合并操作都是伴随着遍历中的退后行为进行的。这样就产生了一个性质,在遍历过程中,一个被遍历过的节点的集合代表元在哪,取决于由树根到该节点的路径上我退后到了哪个节点。这样一来,所有遍历过的节点与当前节点的lca也恰好就是它们的代表元了。在遍历离开当前点之前,先 阅读全文
posted @ 2011-06-20 20:39
undefined2024
阅读(1491)
评论(3)
推荐(0)
摘要:
二分图匹配,匈牙利算法View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 505int uN, vN;bool g[maxn][maxn];int xM[maxn], yM[maxn];bool chk[maxn];int n, p;void input(){ int a, m; memset(g, 0, sizeof(g)); for (int i = 0; i < 阅读全文
posted @ 2011-06-20 18:57
undefined2024
阅读(178)
评论(0)
推荐(0)
摘要:
求二分图的最大独立集 = x + y - maxmatch;View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 505int uN, vN;bool g[maxn][maxn];int xM[maxn], yM[maxn];bool chk[maxn];int n;void input(){ int a, m; memset(g, 0, sizeof(g)); for ( 阅读全文
posted @ 2011-06-20 18:33
undefined2024
阅读(396)
评论(0)
推荐(0)
摘要:
网络流scanf在使用时,%[],中括号中的多个字符用逗号隔开View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 105#define inf 0x3f3f3f3fstruct edge{ int x, y, nxt, c;} bf[(maxn * maxn + maxn) * 2];int n, m, p, con, s, t;int head[maxn], cur[m 阅读全文
posted @ 2011-06-20 16:32
undefined2024
阅读(427)
评论(0)
推荐(0)
摘要:
题意:有一些货物,每个货物有价值和卖出的截至日期,每天可以卖一个货物,问能卖出的最大价值是多少。分析:贪心,按利润排序,然后填入一个数组,f[i]表示第i天是否已经被占用。填入f时找到截至日期之前离截至日期最近的一个未被占用的日子。利用类似并查集的方法优化getanc(i)表示第i天之前最近的未被占用的是第几天View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>usingnamespa 阅读全文
posted @ 2011-06-20 15:25
undefined2024
阅读(1088)
评论(0)
推荐(2)