随笔分类 -  图论相关

图论
 
PKU 3522 slim span
摘要:Slim SpanTime Limit:5000MSMemory Limit:65536KTotal Submissions:2261Accepted:1206DescriptionGiven an undirected weighted graphG, you should find one of spanning trees specified as follows.The graphGis ... 阅读全文
posted @ 2010-05-07 22:56 lee41sum 阅读(456) 评论(0) 推荐(1)
PKU 1364 KING【差分约束系统】
摘要:这图如果是不连通的,SPFA是会出问题的,所以可以增加一个V0的虚拟节点。注意,题目中是>和<,要转换成>=和《=才能应用差分约束,由于是整数,是很好转换的。得到差分约束方程:s[si+ni]-s[si-1]>=cost+1 s[si+ni]-s[si-1]<=cost-1在做SPFA时,如果存在负环则return false,表明不能满足所有的约束方程,如果不出现负... 阅读全文
posted @ 2010-05-01 21:16 lee41sum 阅读(573) 评论(0) 推荐(1)
PKU 3169 layout 【差分约束系统】
摘要:题目:LayoutTime Limit:1000MSMemory Limit:65536KTotal Submissions:1772Accepted:856DescriptionLike everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 <= N <=... 阅读全文
posted @ 2010-05-01 16:39 lee41sum 阅读(845) 评论(0) 推荐(1)
PKU 1125 【简单floyd】
摘要:floyd后遍历下就好代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--#include<iostream>#include<cstring>#include<cstdio>#include<climits&... 阅读全文
posted @ 2010-04-28 11:37 lee41sum 阅读(235) 评论(0) 推荐(0)
PKU 3259
摘要:SPFA找负环,当一个点入队的次数>=n时就证明出现了负环。代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--#include<iostream>#include<cstdio>#include<cstring&g... 阅读全文
posted @ 2010-04-28 00:46 lee41sum 阅读(289) 评论(0) 推荐(0)
PKU 1847 Tram
摘要:有向图,有联系的点之间连边,如果是第一个领接的点,则边的权值为0,后面领接点边的权值为1,建图后做SPFA。[代码] 阅读全文
posted @ 2010-04-25 10:25 lee41sum 阅读(281) 评论(0) 推荐(1)
PKU 1062 昂贵的聘礼
摘要:首先建图,起始点为0点,终止点为1,金币数为边权值,如果有依赖关系则加一条边。然后枚举最短路上等级最高点,每次做最短路时需要满足level小于这个最高点,并且和其previous点等级差不超过m,最短路我使用了spfa.代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlight... 阅读全文
posted @ 2010-04-24 23:51 lee41sum 阅读(410) 评论(0) 推荐(1)
PKU2762 Going from u to v or from v to u 【强连通
摘要:题目地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=2762这题实际上是判断是否是弱连通的,所以首先强连通,然后缩点,对缩点形成的图最多只能有一个入度为0的点,如果有多个入度为0的点,则这两个连通分量肯定是不连通的。 缩点后形成的图形是一棵树,入度为0的点是这颗树的根,这棵树只能是单链,不能有分叉,如果有分叉,则这些分叉之间是不可达的,所以就对这棵树... 阅读全文
posted @ 2010-04-24 16:38 lee41sum 阅读(274) 评论(0) 推荐(1)
PKU2367 Genealogical tree
摘要:http://acm.pku.edu.cn/JudgeOnline/problem?id=2367很水的拓扑排序,我DFS写的。代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--#include<iostream>#include<... 阅读全文
posted @ 2010-04-23 20:04 lee41sum 阅读(208) 评论(0) 推荐(1)
PKU 1094 Sorting It All Out
摘要:题目地址http://acm.pku.edu.cn/JudgeOnline/problem?id=1094  每次读入一条边后,对新图作DFS找是否有环,如果有环则不用进行拓扑排序了,这种属于不能确定的情况。否则进行拓扑排序, 因为拓扑排序的序列可能是不唯一的,拓扑排序不唯一的情况比较好判断,就是如果每次队列中如果有多于一个点(这个点代表入度为0的点),则不唯一,如果不出现这样的点,则有唯一拓扑排... 阅读全文
posted @ 2010-04-23 13:50 lee41sum 阅读(528) 评论(0) 推荐(1)
PKU 1556 The Door
摘要:思路:先建图,建图的根据是判断两点的连线是否和线段有交,如果没交则计算两点的距离,然后做最短路。 贴了个求交的模板,所以代码有点多,我懒了。代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--#include<iostream>#inclu... 阅读全文
posted @ 2010-04-07 19:09 lee41sum 阅读(182) 评论(0) 推荐(1)