There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w. Now given all the cities and flights, together with starting city src and the destination dst, your task is to find the cheapest price from src
拓展dijkstra算法,实现利用vector存储多条路径: #include <iostream> #include <vector> #include <stack> using namespace std; ; ; // 各数组都从下标1开始 int dist[maxnum]; // 表示当前点到源点的最短路径长度 int c[maxnum][maxnum]; // 记录图的两点间路径长度 int n, line; // 图的结点数和路径数 // n -- n n
#include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N=510,M=1e4+10; int n,m,k,dis[N],backup[N]; //dis数组表示dis[i]到起点的距离. struct { int a,b,w; }edge[M]; //bellman-ford可以求出来图中有没有负权回路. //迭代k次返回的数表示:从起点经过不超过k