//-----------Bellman_Ford------------
struct Edge
{
int v,u;
int weight;
}edge[M];
int dist[N];
bool Bellman_Ford(int n,int m,int s)
{
int i,j;
bool flag;
for(i=1;i<=n;i++)
dist[i]=MAXVAL;
dist[s]=0;
for(i=1;i<n;i++)
{
flag=false;
for(j=0;j<m;j++)
{
if(dist[edge[j].v]+edge[j].weight<dist[edge[j].u])
dist[edge[j].u]=dist[edge[j].v]+edge[j].weight,flag=true;
}
if(flag==false) return true;
}///显然写的是单向的!
for(j=0;j<m;j++)
{
if(dist[edge[j].v]+edge[j].weight<dist[edge[j].u])
return false;
}
return true;
}
写的不对或不好的地方,请大虾多多指教! ——Never