558

#include <iostream> #include <cstdio> #include <cstdlib> #define INF 1000000000 #define MX 2005 using namespace std; struct Edge{ int src; int dst; int weight; }; Edge e[MX]; bool bellman(int n,int m,int source) { bool negativecycle =false; int dist[n+5]; dist = 0; for(int i=1;i<n;i++) dist[i]=INF; for(int i=1;i<=n-1;i++) { for(int j=0;j<m;j++) { if(dist[e[j].dst]>dist[e[j].src]+e[j].weight) dist[e[j].dst] = dist[e[j].src]+e[j].weight; } }