上一页 1 2 3 4 5 6 7 8 9 10 ··· 15 下一页
摘要: 无向图的Tarjan和有向图求强连通分量的Tarjan很像...注意几个不同... 1、没有栈..所以判断时先是看点有没有访问过...else的时候就直接更新Low...不需要再来个判断instack.... 2、DFS时不能从 a 递归到了 b..b又马上从a来更新...所以要多加一个notpre..代表递归b时是从哪个点进去的...防止这种情况.. 3、Low相等的点在无向图中就是在一个双连通图中...这个比有向图的方便..有向图还需要用栈来维护..通过判断退栈来判断强连通分量..备注:第三条是一个环的情况 如果多个环就是错的,做HDU 3394。。。所以用low是否相等来判断是否在... 阅读全文
posted @ 2012-04-11 01:44 快乐. 阅读(239) 评论(0) 推荐(0) 编辑
摘要: 题意:N个岛有M个桥相连,烧掉尽可能多的桥,让N个岛仍然相连,问必须不能烧掉的桥的个数及编号。就是求割边割边与割点差不多都是tarjan式的dfs,有两个地方不一样 见代码代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>#define nMAX 10005#define mMAX 200010#define Min(a,b)a<b?a:busing namespace std;int head[nMA 阅读全文
posted @ 2012-04-10 21:38 快乐. 阅读(216) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1144题意:给出一个连通图,求割点的个数代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>#define nMAX 105using namespace std;int map[nMAX][nMAX],dfn[nMAX],low[nMAX];int times,root,n;bool flag[nMAX];int min(int a,int b){ return a<b?a:b;}void tarj 阅读全文
posted @ 2012-04-10 00:21 快乐. 阅读(237) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2117题意:给出一个无向图,不一定连通。问去掉一个点后,图最多分成几部分(几个连通图)第一个割点题代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>#define Max(a,b)a>b?a:b#define Min(a,b)a<b?a:b#define nMAX 10005#define mMAX 2000010using namespace std;int head[nMAX],low[n 阅读全文
posted @ 2012-04-08 21:45 快乐. 阅读(257) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2282题意:有N个盒子,围成一个圈,有的盒子是空的,有的有一个巧克力,有的有多个巧克力,要求最后每个盒子最多一个巧克力。把巧克力移到相邻的盒子需要一步,求最少的步数。构图:有两个及以上的盒子裂点,向空盒子连线,再匹配代码: #include<iostream>#include<cstdio>#include<string>#include<cstring>#define inf 999999#define Min(a,b)a<b?a:b#define Ma 阅读全文
posted @ 2012-04-07 16:25 快乐. 阅读(250) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2853题意:。。。暂略代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>#define Max(a,b)a>b?a:b#define Min(a,b)a<b?a:b#define inf 99999999#define nMAX 55using namespace std;int map[nMAX][nMAX],link[nMAX],slink[nMAX];in 阅读全文
posted @ 2012-04-06 18:42 快乐. 阅读(191) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2426分宿舍,有一句Note that you can never assign a student to a room which he/she has not rated, as the absence of rating indicates that the student cannot live in the room for other reasons负数的不能分配吗?就WA在这里,在研究研究代码:#include<iostream>#include<cstdio>#incl 阅读全文
posted @ 2012-04-06 18:39 快乐. 阅读(190) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3435题意:。。。代码:#include<iostream>#include<cstdio>#include<string>#include<cstring>#define nMAX 10005#define mMAX 99999#define inf 99999999using namespace std;struct Edge{ int u,v,cap,cost,nxt;}edge[mMAX];int head[nMAX],dis[nMAX],qu[nMAX 阅读全文
posted @ 2012-04-06 18:30 快乐. 阅读(234) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1853还不会KM判回路,所以先了解一下最小费用流,第一个最小费用流。。。代码:#include<iostream>#include<cstdio>#include<cstring>#include<string>#define nMAX 300#define mMAX 30000#define inf 9999struct Edge{ int u,v,cap,cost,nxt;}edge[mMAX];int pre[nMAX],head[nMAX],qu[nMA 阅读全文
posted @ 2012-04-04 22:12 快乐. 阅读(185) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=3488依然KM, 可以最小费用流 与HDU1853 差不多,但是1853要判断是否满足回路的的条件,KM还不会判回路,所以做1853时学了最小费用流做的,说是学最小费用流 只是皮毛了。。。代码(KM):#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#define Max(a,b)a&g 阅读全文
posted @ 2012-04-04 22:09 快乐. 阅读(205) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 15 下一页