![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论
文章平均质量分 72
她山之石
这个作者很懒,什么都没留下…
展开
-
poj3268 Silver Cow Party 单源最短路径dijkstra算法
其他牛先从自己家走到x牛家,再从x牛家走回自己家,问这些牛走的最长路。开始我幼稚的遍历了每个点做dijkstra,不出意外TLE了。其实一头牛经过一段路到了x,我们只需要将所有有向路反向,再从x找其他点的最短路,就是其他点到x的最短路。#include#include#include#include#include#include#include#include#inclu原创 2015-07-26 16:06:15 · 524 阅读 · 0 评论 -
hdu2066 最短路 dijkstra
建立超级源点和超级汇点,家是超级源点s=0,超级汇点t=所有城市最大值+1,超级源点到相连的城市的边权=想去的城市到超级汇点的边权=0。只需要求出超级源点到超级汇点的最短路即可。#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>#includ原创 2015-08-25 22:45:23 · 509 阅读 · 0 评论 -
uva11082 最大流和网络流建模
主要是建模想不到,下面两篇讲的不错。http://www.cnblogs.com/xcw0754/p/4646140.htmlhttp://www.cnblogs.com/AOQNRMGYXLMV/p/4280727.html就是将矩阵的行看成一个水管,列看成一个水管,矩阵的值a[i][j]看成第i行流到第j列的流量。第i行的和就是该行流向所有列的流量之和。#include#in原创 2015-08-02 00:05:41 · 458 阅读 · 0 评论 -
hdu2112 spfa
最开始的起点ss和终点tt,一定要在cin之后就要map,否则如下数据 0 aaa bbb 因为n=0,如果没有map,s=name2ID[ss]和t=name2ID[tt]没有被赋值。在这里WA了n次,给跪了。#include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>原创 2015-08-28 22:23:07 · 580 阅读 · 0 评论 -
uva820 最大流模板题
注意以下输出格式,还有就是有重边。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_PRINT 0#define READ_FILE 0us原创 2015-08-03 10:02:36 · 689 阅读 · 0 评论 -
uva1658 最小费用最大流
将编号为2~n-1的点拆为2个点,两点之间连一条边,容量为1,费用为0。注意入边连(i-1)*2,出边连(i-1)*2=1。不同之间容量为1。#include#include#include#include#include#include#include#include#include#include#include#include#include#defin原创 2015-08-02 14:13:07 · 453 阅读 · 0 评论 -
uva12661 Dijkstra
注意有的路可能出现,通过时间>打开时间#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_PRINT 0#define READ_FILE 1原创 2015-08-02 15:57:36 · 461 阅读 · 0 评论 -
uva821 floyd
裸的Floyd算法#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_PRINT 0#define READ_FILE 0using name原创 2015-08-02 19:41:58 · 451 阅读 · 0 评论 -
uva1660 最大流
点连通度和边连通度问题都可以转化为最小割最大流问题。用拆点法,相同点连接一条边,容量为1,不同点连2条边i+1→j,j+1→i,容量为INF。注意scanf的用法,还可以这么用,以前不知道。#include#include#include#include#include#include#include#include#include#include#include原创 2015-08-03 16:42:27 · 987 阅读 · 0 评论 -
hdu1548 最短路/BFS
指定起点和终点,用dijskal求最短路#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_DEBUG 0#define READ_FILE 0u原创 2015-08-14 23:27:27 · 478 阅读 · 0 评论 -
uva10801 Dijkstra
注意在更新maps时有重边,取最小值。dijkstra时,从零开始的也加了60,输出时需要减去60,但是k=0除外。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long原创 2015-08-03 21:17:49 · 383 阅读 · 0 评论 -
UVa10305拓扑排序入门题 可做模板用
#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;/*************************************************原创 2015-07-23 16:31:58 · 459 阅读 · 0 评论 -
UVa10129 判断有向图中是否存在欧拉回路
#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;/*************************************************原创 2015-07-24 02:20:21 · 1029 阅读 · 0 评论 -
UVa 1572 拓扑排序 判断有向图是否有环
#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;/*************************************************原创 2015-07-24 01:36:04 · 530 阅读 · 0 评论 -
uva1395 Kruskal算法求最小生成树
注意并查集的实现方法。#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;const int M_NUM_MAX = 100+5;const原创 2015-07-24 20:26:13 · 411 阅读 · 0 评论 -
匈牙利算法
备个份,后面用到再加题目M67大神的几句话讲解:http://www.matrix67.com/blog/archives/39二分图最大匹配问题匈牙利算法 研究了几个小时,终于明白了。说穿了,就是你从二分图中找出一条路径来,让路径的起点和终点都是还没有匹配过的点,并且路径经过的连线是一条没被匹配、一条已经匹配过,再下一条又没匹配这样交替地出现。找到这样的路径后,显然路径原创 2015-08-06 15:06:54 · 350 阅读 · 0 评论 -
hdu2544 最短路 Bellman_Ford Dijkstra Folyd
Bellman_Ford基本方法,和使用邻接表和队列的优化。由于没有负环而且最短路一定存在,所以不需要判负环那一步。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL原创 2015-08-17 22:42:17 · 503 阅读 · 0 评论 -
hdu1598 有向边 并查集
将所有边排序,从小到大枚举最小边,以这条边为开始找最小生成树(不一定包含所有点),根据find(a)和find(b)是否相等判断a到b是否有边,p[a]表示以a为起点指向能到达的点,即连通。#include#include#include#include#include#include#include#include#include#include#include#inc原创 2015-08-13 00:47:44 · 486 阅读 · 0 评论 -
uva753 folyd EK算法
map没有清空,debug了一晚上。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_PRINT 0#define READ_FILE 0u原创 2015-08-01 21:33:14 · 484 阅读 · 0 评论 -
poj1502 MPI Maelstrom 直接Dijkstra
水的Dijkstra,最短路Dijkstra算法模板。#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;/*********原创 2015-07-26 14:58:48 · 383 阅读 · 0 评论 -
UVa247 Floyd判断可达 深搜求环
1A,主要是将phoneMap转化为connMap,然后深搜求出同在一个圈的id。#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;/****原创 2015-07-25 21:26:51 · 584 阅读 · 0 评论 -
poj 1125 Stockbroker Grapevine Floyd算法求各点之间的最短路
题读了半天,意思是给出每个人的单向联系关系,求找到一个人使消息传播完全传播到所有人的所需时间最小值。本题数据太水了,没有disjoint也AC了。#include#include#include#include#include#include#include#include#include#include#include#include#incl原创 2015-07-26 19:07:36 · 465 阅读 · 0 评论 -
POJ 2240 Bellman算法判正权回路 floyd算法
又WA了好多次,主要错误是map没有clear,判重时直接map.count()了,少一个==0,对每一个点都要做bellman()直到找到正权回路。#include#include#include#include#include#include#include#include#include#include#include#include#include#defin原创 2015-07-27 20:01:51 · 510 阅读 · 0 评论 -
POJ 2387 裸的dijkstra
注意起点为n,终点为1。因为这贡献了几个WA。#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;const int N_MAX原创 2015-07-27 23:16:55 · 386 阅读 · 0 评论 -
POJ 3259 BellmanFord算法和poj2240几乎一样
注意重边和开始点不一定是1#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;const int N_MAX = 1000;原创 2015-07-28 01:32:05 · 447 阅读 · 0 评论 -
POJ 1860 Currency Exchange Bellman-Ford算法求单源最短路径并判断是否有正权回路
#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long longusing namespace std;const int N_MAX = 100+10;const int INF =原创 2015-07-27 15:23:23 · 514 阅读 · 0 评论 -
hdu3790 dijkstra算法
每条路除了距离,还有了费用。这样在我们计算每个点的最小距离d[]和最小费用时,优先保证距离最小d[i]>d[x]+maps[x][i][0],其次保证费用最小d[i]==d[x]+maps[x][i][0]&&cost[i]>cost[x]+maps[x][i][1]。#include#include#include#include#include#include#include原创 2015-08-22 21:31:53 · 455 阅读 · 0 评论 -
hdu5418 最短哈密顿回路
先用floyd求出每两点之间的最短路。一开始我用深搜计算最短哈密顿回路,毫无意外TLE了。 #include<iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<cmath>#include<string>#include<map>#include<set>#include<algorithm>#原创 2015-08-23 17:06:03 · 7820 阅读 · 0 评论 -
POJ 1273 最大流入门题 Edmonds_Karp算法
Edmonds_Karp算法步骤:循环{ 初始化 寻找增广路 没有则退出 根据增广路,更新flow}#include#include#include#include#include#include#include#include#include#include#include#include#include#define OJ_P原创 2015-07-28 23:06:59 · 763 阅读 · 0 评论 -
ACM图论500题(先备个份)
=============================以下是最小生成树+并查集======================================【HDU】1213 How Many Tables 基础并查集★1272 小希的迷宫 基础并查集★1325&&poj1308 Is It A Tree? 基础并查集★1856 More is better 基础并查集★转载 2015-07-30 01:53:53 · 1239 阅读 · 0 评论 -
国家集训队论文分类整理
距离ACM/ICPC的时间越来越少了,选择性地看一些集训队论文是很有必要的。(在此给已经看过所有论文的神牛跪了= =)所以,我在此整理了一下,供大家参考。组合数学计数与统计2001 - 符文杰:《Pólya原理及其应用》2003 - 许智磊:《浅谈补集转化思想在统计问题中的应用》2007 - 周冬:《生成树的计数及其应用》20转载 2015-07-30 02:10:06 · 572 阅读 · 0 评论 -
hdu3371 prim算法求最小生成树
kruskal超时,看discuss说可以不超时。用prim险过,估计改数据了。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_DEBUG 0#原创 2015-08-11 23:32:11 · 501 阅读 · 0 评论 -
hdu1198 二维并查集
将A-K的上下左右有出水口的标记为1,否则标记为0。在地图中根据两个方块的位置关系,判断出水口是否相接。扫描地图时,只需要判断当前方块和上边或者左边是否相接。#include#include#include#include#include#include#include#include#include#include#include#include#include#d原创 2015-08-12 15:53:57 · 559 阅读 · 0 评论 -
hdu1301 prim和kruskal求最小生成树
水题#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_DEBUG 0#define READ_FILE 0using namespace std原创 2015-08-12 01:24:55 · 586 阅读 · 0 评论 -
poj 2315 最小费用最大流入门题
增加一个超级源点和超级汇点,容量为2,费用为0。有重边,且为无向边。所以要用邻接表,需要建4条边。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define原创 2015-07-31 23:52:09 · 685 阅读 · 0 评论 -
hdu1102 kruskal算法求最小生成树
裸的kruskal。#include#include#include#include#include#include#include#include#include#include#include#include#include#define LL long long#define OJ_DEBUG 0#define READ_FILE 0using nam原创 2015-08-07 00:09:31 · 562 阅读 · 0 评论