数据结构图论
文章平均质量分 57
ccDLlyy
不忘初心,方得始终
展开
-
图的存储之邻接表
//个人认为,陈越书上的相关代码过于繁琐,如太多的typedef和较长的变量命名,对于学生,实用性差;所以自己写了个线性表,才疏学浅,还望读者批评指正#include #include #include using namespace std;#define MAXN 100int n,m;struct AdjList{ int v; int weight; struct Adj原创 2016-12-14 13:58:46 · 414 阅读 · 0 评论 -
Proxy(迪克斯特拉算法,山东省第六届ACM竞赛试题)
点击打开链接#include #include #include #include using namespace std;#define INF 0X7FFFFFFFint head[1005],cnt,Min,ind;struct node{ int to; int weight; int next;}edge[20005];struct node1{ int t原创 2017-03-19 14:19:33 · 923 阅读 · 0 评论 -
单源最短路->Dijkstra算法
haha原创 2016-12-14 15:47:28 · 654 阅读 · 0 评论 -
POJ(2387) Til the Cows Come Home
Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get b原创 2017-03-19 15:23:17 · 480 阅读 · 0 评论 -
Prim算法另一种形式
#include #include #include using namespace std;#define MAXN 10000#define MAXM 1000#define INF 0X7FFFFFFFstruct node{//1 原图 2 生成树 生成树要存起来 int to; int weight; int next;}edge1[MAXM],edge2[MAX原创 2017-02-12 21:18:17 · 347 阅读 · 0 评论 -
Poj 2253 Frogger(最小生成树的最大边)
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sun原创 2017-03-28 13:58:39 · 616 阅读 · 0 评论 -
紧急救援(Dijkstra算法)
紧急救援作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数N、M、S、D,其中N(2输出原创 2017-03-31 14:19:35 · 2148 阅读 · 0 评论 -
关于Dijkstra算法的总结
1.只考虑Dijkstra算法模板,不加入其他条件,要想清楚其贪心的过程,对于一个点,可能有在出现最短路径前有了其他路径,但不是最短的,也可能多条路径过来都是最短路,但通到此点的最短路均出现前此点肯定不会去更新其他点,因为更新此点的路径肯定比该点的距离短。一般用book数组标记一个点是不是已经为最短要去更新其他点,因为队列中可能有之前不是最短路径的情况,虽然不用book没关系,反正这个不是最短路径原创 2017-03-31 15:16:49 · 2115 阅读 · 0 评论 -
啊哈算法 最小转机(图的广度优先遍历)
//图的广度优先遍历更适用于所有边的权值相等#include #include #define INF 100000struct node{ int num;//城市编号 int time;//转机次数};struct node queue[100];int head=0;int tail=0;int map[100][100];int book[100];//原创 2016-10-16 09:34:35 · 1449 阅读 · 0 评论 -
图的深度优先遍历和广度优先遍历
哈哈原创 2016-10-16 21:47:22 · 592 阅读 · 0 评论 -
求无向连通图的割点和割边/桥
代码直接整合了求割点和割边://求无向连通图的割点和割边/桥#include #include #include using namespace std;#define MAXN 1000#define MAXM 10000struct node{ int to; int next;}edge[MAXM];int head[MAXN];int cnt;int n,m;原创 2017-02-15 22:27:33 · 965 阅读 · 0 评论 -
最小生成树的Kruskal算法
//最小生成树的Kruskal算法//把所有边的信息存储,排序,按照由小到大顺序依次判断边是否能加入生成树,直到够n-1条边//此处并查集(不相交集)用来判断连通性#include #include #include using namespace std;#define MAXN 1000#define MAXM 10000struct node{ int u; int v原创 2017-02-14 16:25:18 · 337 阅读 · 0 评论 -
图的存储之前向星
#include #include #include using namespace std;#define MAXN 100int n,m;struct edge{ int weight; int next; int to;}edges[MAXN];int head[MAXN];int cnt=0;//顶点从0开始,边从1开始void Init(){//初始化 fo原创 2016-12-14 13:15:48 · 492 阅读 · 0 评论 -
求最小生成树的prim算法
#include #include #include using namespace std;#define MAXN 100#define INFINITY 10000000int n,m;struct edge{ int to; int weight; int next;}edges[MAXN];int head[MAXN];int book[MAXN];int c原创 2016-12-14 14:59:27 · 502 阅读 · 0 评论 -
拓扑排序
//有向图#include #include #include #include using namespace std;#define MAXN 1000struct edge{ int next; int to;}edges[MAXN];int head[MAXN];int n,m,cnt;void Init(){ for(int i=1;i<=m;i++) e原创 2016-12-14 17:44:21 · 294 阅读 · 0 评论 -
邻接表的数组实现
#include #include #include using namespace std;#define MAXN 100000#define MAXM 10000int u[MAXM],v[MAXM],w[MAXM];//存边的信息int first[MAXN],nextEdge[MAXM];//first存顶点的第一条边 //nextEdge存边的下一条边int n,m;原创 2017-02-09 21:39:37 · 519 阅读 · 0 评论 -
图的一些基本概念
图的概念比较杂乱,国内各种书籍对一些概念也是各执己见,比如圈和环.......这里旨在按照一个规则了解一些概念,对于与其他书籍材料的不同,还要看情况再定我们讨论的图大多为简单图->没有环和重边环:一个顶点到他自身的边圈:v1=vn的一条路径。对于有向图,路径长度为1的即为一个环(非简单图)。对于无向图,路径长度为1的还是环,不是圈。且对于没有重边的无向图,u,v,u不算做圈,因为(原创 2017-02-09 10:31:42 · 1758 阅读 · 0 评论 -
多源最短路->Floyd算法
//多源最短路//不能解决 带有负权边的图 的最短路径问题//本代码以无向图为例#include #include #include using namespace std;#define MAXN 100#define INFINITY 10000000int map[MAXN][MAXN];int n,m;void Init(){ for(int i=1;i<=n;i+原创 2016-12-14 16:25:33 · 767 阅读 · 0 评论 -
Bellman-Ford算法
//有向图 能解决负权 对于负圈,表现出一定结果#include #include #include using namespace std;#define MAXN 10000#define MAXM 1000#define INF 0X7FFFFFFFstruct node{ int from; int to; int weight; int next;}edge[M原创 2017-02-11 14:20:34 · 280 阅读 · 0 评论 -
Bellman-Ford算法的队列优化
//Bellman-Ford算法的队列优化//有向图 能解决负权 负圈会呈现一定形式,可加入判断,判断是否有负圈#include #include #include using namespace std;#define MAXN 10000#define MAXM 1000#define INF 0X7FFFFFFFstruct node{ int to; int weig原创 2017-02-11 19:59:28 · 463 阅读 · 0 评论 -
各最短路径算法(图论)比较
原创 2017-02-11 22:28:41 · 558 阅读 · 0 评论 -
啊哈算法 城市地图(图的深度优先遍历)
#include #include #define INF 100000int map[100][100];//存图int book[100];//标记int stack[100];//当前路径int top=-1;int step[100];//最短路径int tops=-1;int n,m;//点数和边数int start,end;//起点和终点int mindis=IN原创 2016-10-16 09:14:08 · 1258 阅读 · 0 评论