![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论
文章平均质量分 74
MiniSheep_CS
编程者如上帝,可以创造万物。
展开
-
hdu5137 How Many Maos Does the Guanxi Worth(ACM/ICPC 西安区域赛现场赛)
How Many Maos Does the Guanxi WorthTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 1371 Accepted Submission(s): 510Problem Desc原创 2015-10-23 20:32:58 · 458 阅读 · 0 评论 -
DFS拓扑排序(算法导论思路)
#include#include#include#include#include#includeusing namespace std;const int maxn = 10005;int color[maxn]; //0代表白色,1代表灰色,2代表黑色vector vec[maxn]; //邻接表 int step; //全局变量代表总步数int stime[maxn];原创 2015-07-14 12:31:06 · 812 阅读 · 0 评论 -
DFS遍历图代码(算法导论思路实现)
#include#include#include#includeusing namespace std;const int maxn = 10005;int color[maxn]; //0代表白色,1代表灰色,2代表黑色vector vec[maxn]; //邻接表 int step; //全局变量代表总步数int stime[maxn]; //每个点遍历的时候的起始时间i原创 2015-07-14 10:57:58 · 531 阅读 · 0 评论 -
前向星
我们首先来看一下什么是前向星.前向星是一种特殊的边集数组,我们把边集数组中的每一条边按照起点从小到大排序,如果起点相同就按照终点从小到大排序,并记录下以某个点为起点的所有边在数组中的起始位置和存储长度,那么前向星就构造好了.用len[i]来记录所有以i为起点的边在数组中的存储长度.用head[i]记录以i为边集在数组中的第一个存储位置.转载 2015-07-27 11:06:07 · 1753 阅读 · 0 评论 -
POJ2387 Til the Cows Come Home(dijkstra + heap 或 SPFA)
Til the Cows Come HomeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 33716 Accepted: 11416DescriptionBessie is out in the field and wants to get back t原创 2015-07-06 17:07:56 · 437 阅读 · 0 评论 -
POJ2243 Knight Moves(A*算法)
Knight MovesTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12345 Accepted: 6963DescriptionA friend of you is doing research on the Traveling Knight Pro原创 2015-06-25 22:16:36 · 738 阅读 · 0 评论 -
POJ Out of Hay(2395 prim最小生成树)
Out of HayTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11814 Accepted: 4628DescriptionThe cows have run out of hay, a horrible event that must be remed原创 2015-03-18 22:30:36 · 388 阅读 · 0 评论 -
POJ2240 Arbitrage(floyd算法的变形运用)
ArbitrageTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 16745 Accepted: 7035DescriptionArbitrage is the use of discrepancies in currency exchange rates原创 2015-03-18 13:58:09 · 395 阅读 · 0 评论 -
HDU2063 过山车(二分图匹配-匈牙利算法模版题)
过山车Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12822 Accepted Submission(s): 5628Problem DescriptionRPG girls今天和大家一起去游乐场玩,终于可原创 2015-03-29 15:07:38 · 516 阅读 · 0 评论 -
有向图的强联通分量Tarjan算法模版(hdu1269)
迷宫城堡Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9341 Accepted Submission(s): 4170Problem Description为了训练小希的方向感,Gardon建立了一座大城堡原创 2015-07-19 22:03:16 · 414 阅读 · 0 评论 -
POJ2230 Watchcow(欧拉回路)
WatchcowTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 6467 Accepted: 2819 Special JudgeDescriptionBessie's been appointed the new watch-cow for th原创 2015-08-14 13:42:58 · 504 阅读 · 0 评论 -
POJ1986 Distance Queries(LCA最近公共祖先)
Distance QueriesTime Limit: 2000MS Memory Limit: 30000KTotal Submissions: 10604 Accepted: 3746Case Time Limit: 1000MSDescriptionFarmer John's cows refused原创 2015-08-19 20:39:17 · 1156 阅读 · 0 评论 -
POJ2485 Highways(prim和Kruskal最小生成树两种解法)
HighwaysTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 23459 Accepted: 10850DescriptionThe island nation of Flatopia is perfectly flat. Unfortunately,原创 2015-03-19 11:17:45 · 515 阅读 · 0 评论 -
POJ3159 Candies(差分约束 PS:此题spfa+队列过不了,spfa + stack才能过)
CandiesTime Limit: 1500MS Memory Limit: 131072KTotal Submissions: 25914 Accepted: 7074DescriptionDuring the kindergarten days, flymouse was the monitor of his原创 2015-08-27 22:39:07 · 597 阅读 · 0 评论 -
POJ1364 King(差分约束 SPFA)
KingTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 11146 Accepted: 4081DescriptionOnce, in one kingdom, there was a queen and that queen was expectin原创 2015-08-27 21:03:23 · 418 阅读 · 0 评论 -
图的广度优先遍历和深度优先遍历(基于链式前向星)
#include#include #includeusing namespace std;const int maxn = 100001;int head[maxn];bool vis[maxn];bool bvis[maxn];queue que;struct EdgeNode{ int to; int w; int next;};EdgeNode Edge原创 2015-08-12 23:10:38 · 933 阅读 · 0 评论 -
HDU2449 Remmarguts' Date(第k短路)
Remmarguts' DateTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 24007 Accepted: 6535Description"Good man never makes girls wait or breaks an appointme原创 2015-08-27 12:55:17 · 810 阅读 · 0 评论 -
前向星和链式前向星
前向星:#include#include#includeusing namespace std;const int maxn = 100001;int head[maxn]; //储存起点为vi的第一条边的位置int n,m;struct Node{ int from; int to; int w; }edge[maxn*3];bool cmp(Node a,原创 2015-08-12 19:51:11 · 520 阅读 · 0 评论 -
POJ2560 Freckles(prim最小生成树)
FrecklesTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7839 Accepted: 3763DescriptionIn an episode of the Dick Van Dyke show, little Richie connects原创 2015-08-15 13:48:04 · 496 阅读 · 0 评论 -
POJ3164 Command Network(最小树形图)
Command NetworkTime Limit: 1000MS Memory Limit: 131072KTotal Submissions: 14736 Accepted: 4232DescriptionAfter a long lasting war on words, a war on arms fina原创 2015-08-19 14:42:26 · 350 阅读 · 0 评论 -
POJ3020 Antenna Placement(二分图匹配 匈牙利算法)
Antenna PlacementTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7044 Accepted: 3498DescriptionThe Global Aerial Research Centre has been allotted the tas原创 2015-03-29 18:03:56 · 449 阅读 · 0 评论 -
POJ1125 Stockbroker Grapevine(最短路floyd算法)
Stockbroker GrapevineTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 28312 Accepted: 15711DescriptionStockbrokers are known to overreact to rumours. You原创 2015-03-17 16:39:32 · 412 阅读 · 0 评论 -
hdu1162(并查集+Kruskal最小生成树)-- Eddy's picture
Eddy's pictureTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7097 Accepted Submission(s): 3588Problem DescriptionEddy begins to原创 2014-11-05 19:49:20 · 556 阅读 · 0 评论 -
POJ1860 Currency Exchange(Bellman-ford的变形)
Currency ExchangeTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 21433 Accepted: 7680DescriptionSeveral currency exchange points are working in our city原创 2015-03-15 11:05:41 · 435 阅读 · 0 评论 -
求解无向图的割点和桥
无向图的割点和桥割点和桥的概念:对于无向图G,如果删除某个点u后,连通分量数目增加(本来为一个连通集,现在变为多个),称u为图的割点。对于连通图,割点就是删除之后不再连通的点。当然了,桥也同理,只不过桥是边,也称为割边,如果删掉(u,v)之后连通分量数目增加,那么我们称(u,v)这条边为桥(割边)。求割点和桥的方法:①很容易想到的,暴力每个结点,然后用DFS判断连通分量是否增加,时原创 2015-02-11 20:19:45 · 823 阅读 · 0 评论 -
Kruskal最小生成树算法
#include#include#includeusing namespace std;const int maxn = 1001;int fa[maxn];int N,M;struct edge{ int x,y,w; edge(int x = 0,int y = 0,int w = 0):x(x),y(y),w(w) {}}e[maxn];bool cmp(e原创 2015-02-09 20:52:14 · 504 阅读 · 0 评论 -
网络流之最大流(Edmonds-Karp算法和Dinic算法)
Ford-Fulkerson算法的基本思路:Ford-Fulkerson算法是求解最大流的基本算法,主要思想是,每次在残量网络中寻找一条从源到汇的路径(称为增广路径),并沿着这条路径增加流量,该算法的改进为Edmonds-Karp算法,与Ford-Fulkerson算法基本无异。Edmonds-karp算法的复杂度为O(|V|*|E|²),在稀疏图(边少点多)中可以得到不错的运行效率。原创 2015-02-07 14:47:10 · 1314 阅读 · 0 评论 -
图论之无权最短路径
无权最短路径顾名思义是边没有权值,所以我们可以把所有的边都赋值为1,求最短路径可以采用广度优先搜索(BFS),该方法按层处理顶点,距开始点最近的那些顶点首先被求值,而最远的那些顶点最后被求值。这很像对树的层序遍历。首先先把不通的路径置为无穷大(我这里置为-1),可以通的路置为1,然后运用广度优先搜索(使用的是队列实现),先取一个点作为始发点,这里取v3,然后把v3加入队列,然后一次寻找可以通的路,原创 2015-02-03 12:22:30 · 669 阅读 · 0 评论 -
bellman-ford算法(判断是否存在负环)
Bellman-ford算法的一个重要应用是判负环。在迭代n-1次后如果还可以进行松弛操作,说明一定存在负环。如果采用队列实现,那么当某个结点入队了n次时可以判断出存在负环,代码如下:#include#include#include#include#include#includeusing namespace std;const int maxn = 1001;struct E原创 2015-02-04 19:57:41 · 4560 阅读 · 0 评论 -
图论之拓扑排序
引例:首先先举一个拓扑排序比较贴近实际的例子吧。比如我想修操作系统这门课,假设学校要求必须先修数据结构和C语言,我必须满足修过数据结构和c语言才可以修操作系统这门课。但是有一个很奇怪的问题就是如果反过来如果要求学C语言和数据结构之前要学操作系统,那么就会出现问题,所以拓扑排序的充要条件就是不能出现回路,即出发点和终点都是自身的情况。实现:寻找一个尚未分配拓扑编号的入度为0的顶点,如原创 2015-01-31 21:46:51 · 463 阅读 · 0 评论 -
最短路算法(Floyd)
Floyd算法又称为,插点法,是一种用于寻找给定的加权图中多源点之间最短路径的算法。该算法名称以创始人之一、1978年图灵奖获得者、斯坦福大学计算机科学系教授罗伯特·弗洛伊德命名。原创 2014-11-04 14:08:23 · 445 阅读 · 0 评论 -
POJ2367(拓扑排序)
Genealogical treeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3233 Accepted: 2182 Special JudgeDescriptionThe system of Martians' blood relations i原创 2015-03-25 15:21:40 · 454 阅读 · 0 评论 -
POJ3259 Wormholes(Bellman-ford 负环)
WormholesTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 33194 Accepted: 12085DescriptionWhile exploring his many farms, Farmer John has discovered a原创 2015-03-15 14:09:13 · 332 阅读 · 0 评论 -
POJ1789 Truck History(prim最小生成树)
Truck HistoryTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 19866 Accepted: 7676DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types原创 2015-03-19 10:06:33 · 361 阅读 · 0 评论 -
hdu1879(Kruskal最小生成树)--继续畅通工程
继续畅通工程Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14396 Accepted Submission(s): 6270Problem Description省政府“畅通工程”的目标是使全省任何两个村庄原创 2014-11-07 10:56:04 · 500 阅读 · 0 评论 -
hdu2066 一个人的旅行(Dijkstra求最短路)
一个人的旅行Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20126 Accepted Submission(s): 7024Problem Description虽然草儿是个路痴(就是在杭电待了一年多,居然原创 2014-11-07 22:30:03 · 559 阅读 · 0 评论 -
hdu2544(裸最短路dijkstra)
最短路Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 34140 Accepted Submission(s): 14820Problem Description在每年的校赛里,所有进入决赛的同学都会获原创 2014-12-08 12:55:57 · 480 阅读 · 0 评论 -
hdu1102(Constructing Roads)--prim最小生成树
Constructing RoadsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14545 Accepted Submission(s): 5521Problem DescriptionThere are原创 2014-11-04 18:44:01 · 449 阅读 · 0 评论 -
hdu 1863畅通工程(prim最小生成树)
畅通工程Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17968 Accepted Submission(s): 7609Problem Description省政府“畅通工程”的目标是使全省任何两个村庄间都原创 2014-11-05 10:22:09 · 454 阅读 · 0 评论 -
hdu3665 seaside(floyd算法)
SeasideTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1130 Accepted Submission(s): 825Problem DescriptionXiaoY is living in原创 2014-11-08 11:10:45 · 482 阅读 · 0 评论