算法 Bellman-Ford(G, w, s)for each vertex v 属于 V[G]d[v] = 无穷大p[v] = NILd[s] = 0for i = 1 to |V[G]| - 1relax(u, v, w)for each edge(u, v)属于E[G]if d[v] > d[u] + w(u, v)return falsereturn true n表示图中的顶点数,m表示边数,时间复杂度为O(nm) 实践 UVa11090 Going in Cycle!!