找负环 bellman ford 算法

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include <algorithm>
#include <ctype.h>
#include <cmath>
#include <queue>
#include <vector>
#define inf 1e9+7
#define pi acos(-1)
#define natrule exp(1)
using namespace std;
struct edge{
    int to,from,weight;
};
int d[1005];
edge eg[1005];
bool find_negtive_loop(int m, int n){
    memset(d,0,sizeof(d));//随意设置一个除了inf之外的值
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            edge e=eg[i];
            if(d[e.to]>d[e.from]+e.weight){
                d[e.to]=d[e.from]+e.weight;
                if(i==n-1) return true;
            }
        }
    }
    return false;
}
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(75, 209, 87);"><span style="font-variant-ligatures: no-common-ligatures">//dij prim </span><span style="line-height: normal; font-family: 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures;">堆优化</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="line-height: normal; font-family: 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures;">的</span><span style="font-variant-ligatures: no-common-ligatures"> egde</span><span style="line-height: normal; font-family: 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures;">类型不同于</span><span style="font-variant-ligatures: no-common-ligatures"> kruskal </span><span style="line-height: normal; font-family: 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures;">还有</span><span style="font-variant-ligatures: no-common-ligatures">bellman —— ford</span></p>

    原文作者:Bellman - ford算法
    原文地址: https://blog.csdn.net/qq_34271269/article/details/51920902
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞