目录
1.dijkstra邻接矩阵
2.Emergency
3.Travel Plan
4.bellman ford
5.Emergency(bellman)
6.spfa
7.Floyd
1.dijkstra邻接矩阵
int n,g[maxv][maxv];
int d[maxv];
bool vis[maxv]={false};
void dijkstra(int s){
fill(d,d+maxv,inf);
d[s]=0;
for(int i=0;i
2.Emergency
#include
#include
#include
#include
#include
3.Travel Plan
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
4.bellman ford
struct node{
int v,dis;
};
const int maxv=5005;
const int inf=100000000;
vector adj[maxv];
int n;
int d[maxv];
bool bellman(int s){
fill(d,d+maxv,inf);
d[s]=0;
for(int i=0;i
5.Emergency(bellman)
#include
#include
#include
#include
#include
6.spfa
bool spfa(int s){
fill(d,d+maxv,inf);
memset(inq,false,sizeof(inq));
memset(num,0,sizeof(num));
queue q;
q.push(s);
inq[s]=true;
num[s]++;
d[s]=0;
while(!q.empty()){
int u=q.front();
q.pop();
inq[u]=false;
for(int j=0;jn) return false;
}
}
}
}
return true;
}
7.Floyd
void floyd(){
for(int k=0;k