def negative_edge_cycle(G, weight='weight'):
 newnode = generate_unique_node()
 G.add_edges_from([(newnode, n) for n in G])
 try:
  bellman_ford_predecessor_and_distance(G, newnode, weight)
 except nx.NetworkXUnbounded:
  return True
 finally:
  G.remove_node(newnode)
 return False

def negative_edge_cycle ( G , weight = 'weight' ) : newnode = generate_unique_node ( ) G . add_edges_from ( [ ( newnode , n ) for n in G ] ) try : bellman_ford_predecessor_and_distance ( G , newnode , weight ) except nx . NetworkXUnbounded : return True finally : G . remove_node ( newnode ) return False
return true if there exists a negative edge cycle anywhere in g .