{"id":76540,"date":"2026-02-22T18:17:38","date_gmt":"2026-02-22T10:17:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76540.html"},"modified":"2026-02-22T18:17:38","modified_gmt":"2026-02-22T10:17:38","slug":"%e8%af%a6%e8%a7%a3%e6%9c%80%e7%9f%ad%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76540.html","title":{"rendered":"\u8be6\u89e3\u6700\u77ed\u8def\u5f84"},"content":{"rendered":"<h5 id=\"%E2%80%8B%E7%BC%96%E8%BE%91\" style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101735-699ad7bf3de03.gif\" \/><\/h5>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E2%80%8B%E7%BC%96%E8%BE%91-toc\" style=\"margin-left:120px\">\u200b\u7f16\u8f91<\/p>\n<p id=\"%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84-toc\" style=\"margin-left:120px\">\u6700\u77ed\u8def\u5f84<\/p>\n<p id=\"Dijkstra%E7%AE%97%E6%B3%95%EF%BC%88%E5%8D%95%E6%BA%90%EF%BC%89-toc\" style=\"margin-left:160px\">Dijkstra\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09;<\/p>\n<p id=\"%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B3-toc\" style=\"margin-left:200px\">\u7b97\u6cd5\u601d\u60f3<\/p>\n<p id=\"%E7%AE%97%E6%B3%95%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:200px\">\u7b97\u6cd5\u6b65\u9aa4<\/p>\n<p id=\"%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:200px\">\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p id=\"%C2%A0%E4%BB%A3%E7%A0%81%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:200px\">\u00a0\u4ee3\u7801\u6d4b\u8bd5<\/p>\n<p id=\"%E7%BC%BA%E7%82%B9-toc\" style=\"margin-left:200px\">\u7f3a\u70b9<\/p>\n<p id=\"Bellman-Ford%E7%AE%97%E6%B3%95%EF%BC%88%E5%8D%95%E6%BA%90%EF%BC%89-toc\" style=\"margin-left:160px\">Bellman-Ford\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09;<\/p>\n<p id=\"%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B3-toc\" style=\"margin-left:200px\">\u7b97\u6cd5\u601d\u60f3<\/p>\n<p id=\"%E7%AE%97%E6%B3%95%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:200px\">\u7b97\u6cd5\u6b65\u9aa4<\/p>\n<p id=\"%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:200px\">\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p id=\"%E4%BB%A3%E7%A0%81%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:200px\">\u4ee3\u7801\u6d4b\u8bd5<\/p>\n<p id=\"Floyd-Warshall%E7%AE%97%E6%B3%95-toc\" style=\"margin-left:160px\">Floyd-Warshall\u7b97\u6cd5&#xff08;\u591a\u6e90&#xff09;<\/p>\n<p id=\"%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B3-toc\" style=\"margin-left:200px\">\u7b97\u6cd5\u601d\u60f3<\/p>\n<p id=\"%E7%AE%97%E6%B3%95%E6%AD%A5%E9%AA%A4-toc\" style=\"margin-left:200px\">\u7b97\u6cd5\u6b65\u9aa4<\/p>\n<p id=\"%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:200px\">\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p id=\"%E4%BB%A3%E7%A0%81%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:200px\">\u4ee3\u7801\u6d4b\u8bd5<\/p>\n<hr id=\"hr-toc\" \/>\n<h5 id=\"%E6%9C%80%E7%9F%AD%E8%B7%AF%E5%BE%84\">\u6700\u77ed\u8def\u5f84<\/h5>\n<p>\u6700\u77ed\u8def\u5f84\u95ee\u9898&#xff1a;\u4ece\u5728\u5e26\u6743\u56fe\u7684\u67d0\u4e00\u9876\u70b9\u51fa\u53d1&#xff0c;\u627e\u51fa\u4e00\u6761\u901a\u5f80\u53e6\u4e00\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84&#xff0c;\u6700\u77ed\u4e5f\u5c31\u662f\u6cbf\u8def\u5f84\u5404\u8fb9\u7684\u6743\u503c\u603b\u548c\u8fbe\u5230\u6700\u5c0f\u3002<\/p>\n<h6 id=\"Dijkstra%E7%AE%97%E6%B3%95%EF%BC%88%E5%8D%95%E6%BA%90%EF%BC%89\">Dijkstra\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09;<\/h6>\n<p>Dijkstra\u7b97\u6cd5\u7531\u8377\u5170\u8ba1\u7b97\u673a\u79d1\u5b66\u5bb6Edsger W. Dijkstra\u57281956\u5e74\u63d0\u51fa&#xff0c;\u9002\u7528\u4e8e\u542b\u6709<span style=\"color:#fe2c24\">\u975e\u8d1f\u6743\u91cd<\/span>\u7684\u6709\u5411\u56fe\u6216\u65e0\u5411\u56fe\u3002<\/p>\n<h6 id=\"%E7%AE%97%E6%B3%95%E6%80%9D%E6%83%B3\">\u7b97\u6cd5\u601d\u60f3<\/h6>\n<p>Dijkstra\u7b97\u6cd5\u7684\u57fa\u672c\u601d\u60f3\u662f\u8d2a\u5fc3\u7b97\u6cd5\u3002\u5b83\u7ef4\u62a4\u4e00\u4e2a\u8ddd\u79bb\u6570\u7ec4&#xff0c;\u8be5\u6570\u7ec4\u8bb0\u5f55\u4e86\u4ece\u6e90\u70b9\u5230\u56fe\u4e2d\u6bcf\u4e2a\u9876\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\u4f30\u8ba1\u503c\u3002\u7b97\u6cd5\u91cd\u590d\u4ece\u672a\u5904\u7406\u7684\u9876\u70b9\u4e2d\u9009\u62e9\u5177\u6709\u6700\u5c0f\u8ddd\u79bb\u4f30\u8ba1\u503c\u7684\u9876\u70b9&#xff0c;\u5e76\u66f4\u65b0\u5176\u90bb\u5c45\u9876\u70b9\u7684\u8ddd\u79bb\u4f30\u8ba1\u503c&#xff0c;\u76f4\u5230\u6240\u6709\u9876\u70b9\u90fd\u88ab\u5904\u7406\u3002<\/p>\n<h6 id=\"%E7%AE%97%E6%B3%95%E6%AD%A5%E9%AA%A4\">\u7b97\u6cd5\u6b65\u9aa4<\/h6>\n<p>1.\u521d\u59cb\u5316&#xff1a; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u8ddd\u79bb\u6570\u7ec4dist[]&#xff0c;\u7528\u4e8e\u5b58\u50a8\u4ece\u6e90\u70b9\u5230\u56fe\u4e2d\u6bcf\u4e2a\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u7684\u4f30\u8ba1\u8ddd\u79bb\u3002\u5c06\u6240\u6709\u9876\u70b9\u7684\u8ddd\u79bb\u521d\u59cb\u5316\u4e3a\u65e0\u7a77\u5927&#xff08;\u9664\u4e86\u6e90\u70b9&#xff0c;\u5176\u8ddd\u79bb\u521d\u59cb\u5316\u4e3a0&#xff09;\u3002 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u521b\u5efa\u4e00\u4e2a\u4e00\u7ef4\u5e03\u5c14\u6570\u7ec4visited[]&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u9876\u70b9\u662f\u5426\u5df2\u88ab\u5904\u7406&#xff08;\u5373\u662f\u5426\u5df2\u7ecf\u627e\u5230\u4e86\u4ece\u6e90\u70b9\u5230\u8be5\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84&#xff09;\u3002\u521d\u59cb\u65f6&#xff0c;\u6240\u6709\u9876\u70b9\u90fd\u672a\u88ab\u5904\u7406\u3002 2.\u5faa\u73af\u5904\u7406&#xff1a;<\/p>\n<p>\u4ece\u672a\u88ab\u6807\u8bb0\u5904\u7406\u7684\u70b9\u8fde\u51fa\u53bb\u7684\u6240\u6709\u8fb9\u4e2d\u9009\u51fa\u8ddd\u79bb\u6700\u77ed\u7684\u8fb9&#xff0c;\u7136\u540e\u5c06\u8be5\u8fb9\u7684\u6e90\u8282\u70b9u\u6807\u8bb0\u4e3a\u5904\u7406\u8fc7\u3002 \u904d\u5386\u9876\u70b9u\u7684\u6240\u6709\u90bb\u5c45\u9876\u70b9v&#xff0c;\u5bf9\u4e8e\u6bcf\u4e2a\u90bb\u5c45\u9876\u70b9v&#xff0c;\u5982\u679c\u901a\u8fc7\u9876\u70b9u\u5230\u8fbe\u9876\u70b9v\u7684\u8ddd\u79bb&#xff08;\u5373dist[u] &#043; matrix(u, v)&#xff09;\u5c0f\u4e8e\u5f53\u524d\u8bb0\u5f55\u7684dist[v]&#xff0c;\u5219\u66f4\u65b0dist[v]\u4e3a\u8fd9\u4e2a\u66f4\u5c0f\u7684\u503c\u3002 3.\u7ed3\u675f&#xff1a; \u5f53\u6240\u6709\u9876\u70b9\u90fd\u88ab\u5904\u7406\u540e&#xff0c;\u7b97\u6cd5\u7ed3\u675f\u3002\u6b64\u65f6&#xff0c;dist[]\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u5c31\u662f\u4ece\u6e90\u70b9\u5230\u56fe\u4e2d\u6bcf\u4e2a\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6\u3002<\/p>\n<p>\u4e3a\u4e86\u8bb0\u5f55\u4e0b\u6700\u77ed\u8def\u5f84\u7684\u6574\u6761\u8def\u5f84\u662f\u600e\u6837\u7684&#xff0c;\u4f7f\u7528\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4pPath[]\u6765\u6807\u8bb0\u6bcf\u4e2a\u70b9\u5728\u6700\u77ed\u8def\u5f84\u4e2d\u524d\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48&#xff0c;\u8fd9\u6837\u5c31\u80fd\u591f\u77e5\u9053\u6700\u77ed\u8def\u5f84\u7684\u6574\u6761\u8def\u5f84\u662f\u600e\u6837\u7684\u4e86&#xff08;\u5e76\u67e5\u96c6\u601d\u60f3&#xff09;\u3002<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n^2)\u3002<\/p>\n<p>\u56fe\u89e3&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"519\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101735-699ad7bf59283.png\" width=\"1087\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"560\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101735-699ad7bf9d601.png\" width=\"1098\" \/><\/p>\n<h6 id=\"%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0\">\u4ee3\u7801\u5b9e\u73b0<\/h6>\n<p>Constant.java<\/p>\n<p>public class Constant {<br \/>\n    public static final int MAX &#061; Integer.MAX_VALUE;<br \/>\n} <\/p>\n<p>Dijkstra.java<\/p>\n<p>public void dijkstra(char vSrc,int[] dist,int[] pPath) {<br \/>\n    int srcIndex &#061; getIndexOfV(vSrc);<br \/>\n    \/\/\u8ddd\u79bb\u6570\u636e\u521d\u59cb\u5316<br \/>\n    Arrays.fill(dist,Constant.MAX);<br \/>\n    dist[srcIndex] &#061; 0;<br \/>\n    \/\/\u8def\u5f84\u6570\u7ec4\u521d\u59cb\u5316<br \/>\n    Arrays.fill(pPath,-1);<br \/>\n    pPath[srcIndex] &#061; srcIndex;<br \/>\n    \/\/\u5f53\u524d\u9876\u70b9\u662f\u5426\u88ab\u8bbf\u95ee\u8fc7<br \/>\n    int n &#061; arrayV.length;<br \/>\n    boolean[] visted &#061; new boolean[n];<\/p>\n<p>    \/\/n\u4e2a\u9876\u70b9,\u8981\u66f4\u65b0n\u6b21&#xff0c;\u6bcf\u6b21\u90fd\u8981\u4ece0\u4e0b\u6807\u5f00\u59cb&#xff0c;\u627e\u5230\u4e00\u4e2a\u6700\u5c0f\u503c<br \/>\n    for (int k &#061; 0; k &lt; n; k&#043;&#043;) {<br \/>\n        int min &#061; Constant.MAX;<br \/>\n        int u &#061; srcIndex;<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            if(visted[i] &#061;&#061; false &amp;&amp; dist[i] &lt; min) {<br \/>\n                min &#061; dist[i];<br \/>\n                u &#061; i;\/\/\u66f4\u65b0u\u4e0b\u6807<br \/>\n            }<br \/>\n        }<br \/>\n        visted[u] &#061; true;\/\/u:s<br \/>\n        \/\/\u677e\u5f1bu\u8fde\u63a5\u51fa\u53bb\u7684\u6240\u6709\u7684\u9876\u70b9 v<br \/>\n        for (int v &#061; 0; v &lt; n; v&#043;&#043;) {<br \/>\n            if(visted[v] &#061;&#061; false &amp;&amp; matrix[u][v] !&#061; Constant.MAX<br \/>\n                    &amp;&amp; dist[u] &#043; matrix[u][v] &lt; dist[v]) {<br \/>\n                dist[v] &#061; dist[u] &#043; matrix[u][v];<br \/>\n                pPath[v] &#061; u;\/\/\u66f4\u65b0\u5f53\u524d\u7684\u8def\u5f84<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h6 id=\"%C2%A0%E4%BB%A3%E7%A0%81%E6%B5%8B%E8%AF%95\">\u00a0\u4ee3\u7801\u6d4b\u8bd5<\/h6>\n<p>public void printShortPath(char vSrc,int[] dist,int[] pPath) {<br \/>\n    int srcIndex &#061; getIndexOfV(vSrc);<\/p>\n<p>    int n &#061; arrayV.length;<\/p>\n<p>    for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n        \/\/i\u4e0b\u6807\u6b63\u597d\u662f\u8d77\u70b9  \u5219\u4e0d\u8fdb\u884c\u8def\u5f84\u7684\u6253\u5370<br \/>\n        if(i !&#061; srcIndex) {<br \/>\n            ArrayList&lt;Integer&gt; path &#061; new ArrayList&lt;&gt;();<br \/>\n            int pathI &#061; i;<br \/>\n            while (pathI !&#061; srcIndex) {<br \/>\n                path.add(pathI);<br \/>\n                pathI &#061; pPath[pathI];<br \/>\n            }<br \/>\n            path.add(srcIndex);<\/p>\n<p>            Collections.reverse(path);<\/p>\n<p>            for (int pos : path) {<br \/>\n                System.out.print(arrayV[pos]&#043;&#034; -&gt; &#034;);<br \/>\n            }<br \/>\n            System.out.println(dist[i]);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>public static void testGraphDijkstra() {<br \/>\n    String str &#061; &#034;syztx&#034;;<br \/>\n    char[] array &#061; str.toCharArray();<br \/>\n    GraphByMatrix g &#061; new GraphByMatrix(str.length(),true);<br \/>\n    g.initArrayV(array);<br \/>\n    g.addEdge(&#039;s&#039;, &#039;t&#039;, 10);<br \/>\n    g.addEdge(&#039;s&#039;, &#039;y&#039;, 5);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;t&#039;, 3);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;x&#039;, 9);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;z&#039;, 2);<br \/>\n    g.addEdge(&#039;z&#039;, &#039;s&#039;, 7);<br \/>\n    g.addEdge(&#039;z&#039;, &#039;x&#039;, 6);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;y&#039;, 2);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;x&#039;, 1);<br \/>\n    g.addEdge(&#039;x&#039;, &#039;z&#039;, 4);<\/p>\n<p>    int[] dist &#061; new int[array.length];<br \/>\n    int[] parentPath &#061; new int[array.length];<br \/>\n    g.dijkstra(&#039;s&#039;, dist, parentPath);<\/p>\n<p>    g.printShortPath(&#039;s&#039;, dist, parentPath);<br \/>\n} <\/p>\n<p>\u00a0\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"128\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101735-699ad7bfe8b75.png\" width=\"251\" \/><\/p>\n<h6 id=\"%E7%BC%BA%E7%82%B9\">\u7f3a\u70b9<\/h6>\n<p>\u65e0\u6cd5\u89e3\u51b3\u8fb9\u6743\u4e3a\u8d1f\u7684\u6700\u77ed\u8def\u5f84\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"193\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c002fd3.png\" width=\"247\" \/><\/p>\n<p>\u5bf9\u4e8e\u4e0a\u9762\u7684\u60c5\u51b5&#xff0c;\u6211\u4eec\u77e5\u9053&#xff0c;Dijkstra\u7b97\u6cd5\u4e00\u5b9a\u4f1a\u9009\u62e9\u201c\u7eff\u8272\u201d\u7684\u90a3\u6761\u8def&#xff0c;\u4f46\u662f\u201c\u7ea2\u8272\u201d\u7684\u90a3\u6761\u8def\u662f\u6700\u77ed\u7684&#xff0c;\u8fd9\u5c31\u662fDijkstra\u7b97\u6cd5\u65e0\u6cd5\u89e3\u51b3\u7684\u8fb9\u6743\u4e3a\u8d1f\u7684\u60c5\u51b5&#xff0c;\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684Bellman-Ford\u7b97\u6cd5\u3002<\/p>\n<h6 id=\"Bellman-Ford%E7%AE%97%E6%B3%95%EF%BC%88%E5%8D%95%E6%BA%90%EF%BC%89\">Bellman-Ford\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09;<\/h6>\n<p>Bellman-Ford\u7b97\u6cd5\u7531\u7406\u67e5\u5fb7\u00b7\u8d1d\u5c14\u66fc\u548c\u83b1\u65af\u7279\u00b7\u798f\u7279\u5171\u540c\u521b\u7acb\u3002\u8be5\u7b97\u6cd5\u7279\u522b\u9002\u7528\u4e8e\u56fe\u4e2d\u5b58\u5728\u8d1f\u6743\u8fb9\u7684\u60c5\u51b5&#xff0c;\u8fd9\u662f\u5176\u76f8\u5bf9\u4e8e\u5176\u4ed6\u7b97\u6cd5&#xff08;\u5982Dijkstra\u7b97\u6cd5&#xff09;\u7684\u4e3b\u8981\u4f18\u52bf\u3002<\/p>\n<h6>\u7b97\u6cd5\u601d\u60f3<\/h6>\n<p>Bellman-Ford\u7b97\u6cd5\u901a\u8fc7\u591a\u6b21\u8fed\u4ee3\u6765\u9010\u6b65\u903c\u8fd1\u6700\u77ed\u8def\u5f84\u7684\u771f\u5b9e\u503c\u3002\u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d&#xff0c;\u7b97\u6cd5\u4f1a\u5c1d\u8bd5\u901a\u8fc7\u6240\u6709\u8fb9\u6765\u66f4\u65b0\u8d77\u70b9\u5230\u5176\u4ed6\u6240\u6709\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\u3002\u5982\u679c\u56fe\u4e2d\u4e0d\u5b58\u5728\u8d1f\u6743\u56de\u8def&#xff0c;\u90a3\u4e48\u7ecf\u8fc7\u6709\u9650\u6b21\u8fed\u4ee3\u540e&#xff0c;\u7b97\u6cd5\u5c06\u6536\u655b\u5230\u6b63\u786e\u7684\u6700\u77ed\u8def\u5f84\u89e3\u3002<\/p>\n<h6>\u7b97\u6cd5\u6b65\u9aa4<\/h6>\n<p>1.\u521d\u59cb\u5316\u8ddd\u79bb\u6570\u7ec4dist[]&#xff0c;\u5c06\u8d77\u70b9\u5230\u81ea\u8eab\u7684\u8ddd\u79bb\u8bbe\u4e3a0&#xff0c;\u8d77\u70b9\u5230\u5176\u4ed6\u6240\u6709\u70b9\u7684\u8ddd\u79bb\u8bbe\u4e3a\u65e0\u7a77\u5927\u3002 2.\u6267\u884cn\u6b21\u8fed\u4ee3&#xff08;n\u4e3a\u56fe\u4e2d\u9876\u70b9\u7684\u6570\u91cf&#xff09;&#xff0c;\u6bcf\u6b21\u8fed\u4ee3\u90fd\u5bf9\u6240\u6709\u8fb9\u6267\u884c\u677e\u5f1b\u64cd\u4f5c\u3002 3.\u5728\u7b2cn&#043;1\u6b21\u8fed\u4ee3\u4e2d&#xff0c;\u518d\u6b21\u5bf9\u6240\u6709\u8fb9\u6267\u884c\u677e\u5f1b\u64cd\u4f5c&#xff0c;\u4f46\u8fd9\u6b21\u662f\u4e3a\u4e86\u68c0\u6d4b\u56fe\u4e2d\u662f\u5426\u5b58\u5728\u8d1f\u6743\u56de\u8def\u3002\u5982\u679c\u8fd8\u80fd\u66f4\u65b0\u67d0\u4e9b\u70b9\u7684\u8ddd\u79bb&#xff0c;\u5219\u8bf4\u660e\u56fe\u4e2d\u5b58\u5728\u8d1f\u6743\u56de\u8def\u3002<\/p>\n<p>\u4e3a\u4e86\u8bb0\u5f55\u4e0b\u6700\u77ed\u8def\u5f84\u7684\u6574\u6761\u8def\u5f84\u662f\u600e\u6837\u7684&#xff0c;\u4f7f\u7528\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4pPath[]\u6765\u6807\u8bb0\u6bcf\u4e2a\u70b9\u5728\u6700\u77ed\u8def\u5f84\u4e2d\u524d\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48&#xff0c;\u8fd9\u6837\u5c31\u80fd\u591f\u77e5\u9053\u6700\u77ed\u8def\u5f84\u7684\u6574\u6761\u8def\u5f84\u662f\u600e\u6837\u7684\u4e86&#xff08;\u5e76\u67e5\u96c6\u601d\u60f3&#xff09;\u3002<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6\u8f83\u9ad8&#xff0c;\u4e3aO(n^3)&#xff0c;\u4e0d\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u56fe\u3002<\/p>\n<p>\u56fe\u89e3&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"465\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c01810d.png\" width=\"1073\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"448\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c054c3c.png\" width=\"1112\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"272\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c09093c.png\" width=\"224\" \/><\/p>\n<h6>\u4ee3\u7801\u5b9e\u73b0<\/h6>\n<p>public boolean bellmanFord(char vSrc,int[] dist,int[] pPath) {<br \/>\n    int srcIndex &#061; getIndexOfV(vSrc);<br \/>\n    \/\/\u8ddd\u79bb\u6570\u636e\u521d\u59cb\u5316<br \/>\n    Arrays.fill(dist,Constant.MAX);<br \/>\n    dist[srcIndex] &#061; 0;<br \/>\n    \/\/\u8def\u5f84\u6570\u7ec4\u521d\u59cb\u5316<br \/>\n    Arrays.fill(pPath,-1);<br \/>\n    pPath[srcIndex] &#061; 0;<\/p>\n<p>    int n &#061; arrayV.length;<\/p>\n<p>    for (int k &#061; 0; k &lt; n; k&#043;&#043;) {<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            for (int j &#061; 0; j &lt; n; j&#043;&#043;) {<br \/>\n                if(matrix[i][j] !&#061; Constant.MAX &amp;&amp;<br \/>\n                        dist[i] &#043; matrix[i][j] &lt; dist[j]) {<br \/>\n                    dist[j] &#061; dist[i] &#043; matrix[i][j];<br \/>\n                    pPath[j] &#061; i;<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n        for (int j &#061; 0; j &lt; n; j&#043;&#043;) {<br \/>\n            if(matrix[i][j] !&#061; Constant.MAX &amp;&amp;<br \/>\n                    dist[i] &#043; matrix[i][j] &lt; dist[j]) {<br \/>\n                return false;<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n    return true;<br \/>\n} <\/p>\n<h6 id=\"%E4%BB%A3%E7%A0%81%E6%B5%8B%E8%AF%95\">\u4ee3\u7801\u6d4b\u8bd5<\/h6>\n<p>\u4e0d\u5e26\u8d1f\u6743\u56de\u8def\u7684\u60c5\u51b5<\/p>\n<p>public static void testGraphBellmanFord() {<br \/>\n    String str &#061; &#034;syztx&#034;;<br \/>\n    char[] array &#061; str.toCharArray();<br \/>\n    GraphByMatrix g &#061; new GraphByMatrix(str.length(),true);<br \/>\n    g.initArrayV(array);<br \/>\n    g.addEdge(&#039;s&#039;, &#039;t&#039;, 6);<br \/>\n    g.addEdge(&#039;s&#039;, &#039;y&#039;, 7);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;z&#039;, 9);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;x&#039;, -3);<br \/>\n    g.addEdge(&#039;z&#039;, &#039;s&#039;, 2);<br \/>\n    g.addEdge(&#039;z&#039;, &#039;x&#039;, 7);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;x&#039;, 5);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;y&#039;, 8);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;z&#039;, -4);<br \/>\n    g.addEdge(&#039;x&#039;, &#039;t&#039;, -2);<\/p>\n<p>    int[] dist &#061; new int[array.length];<br \/>\n    int[] parentPath &#061; new int[array.length];<br \/>\n    boolean flg &#061; g.bellmanFord(&#039;s&#039;, dist, parentPath);<br \/>\n    if(flg) {<br \/>\n        g.printShortPath(&#039;s&#039;, dist, parentPath);<br \/>\n    }else {<br \/>\n        System.out.println(&#034;\u5b58\u5728\u8d1f\u6743\u56de\u8def&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"125\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c0a6bd3.png\" width=\"313\" \/><\/p>\n<p>\u5e26\u8d1f\u6743\u56de\u8def\u7684\u60c5\u51b5<\/p>\n<p>public static void testGraphBellmanFord() {<br \/>\n    String str &#061; &#034;syztx&#034;;<br \/>\n    char[] array &#061; str.toCharArray();<br \/>\n    GraphByMatrix g &#061; new GraphByMatrix(str.length(),true);<br \/>\n    g.initArrayV(array);<\/p>\n<p>    \/\/\u8d1f\u6743\u56de\u8def\u5b9e\u4f8b<br \/>\n    g.addEdge(&#039;s&#039;, &#039;t&#039;, 6);<br \/>\n    g.addEdge(&#039;s&#039;, &#039;y&#039;, 7);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;z&#039;, 9);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;x&#039;, -3);<br \/>\n    g.addEdge(&#039;y&#039;, &#039;s&#039;, 1);<br \/>\n    g.addEdge(&#039;z&#039;, &#039;s&#039;, 2);<br \/>\n    g.addEdge(&#039;z&#039;, &#039;x&#039;, 7);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;x&#039;, 5);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;y&#039;, -8);<br \/>\n    g.addEdge(&#039;t&#039;, &#039;z&#039;, -4);<br \/>\n    g.addEdge(&#039;x&#039;, &#039;t&#039;, -2);<\/p>\n<p>    int[] dist &#061; new int[array.length];<br \/>\n    int[] parentPath &#061; new int[array.length];<br \/>\n    boolean flg &#061; g.bellmanFord(&#039;s&#039;, dist, parentPath);<br \/>\n    if(flg) {<br \/>\n        g.printShortPath(&#039;s&#039;, dist, parentPath);<br \/>\n    }else {<br \/>\n        System.out.println(&#034;\u5b58\u5728\u8d1f\u6743\u56de\u8def&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"64\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c0b7e40.png\" width=\"206\" \/><\/p>\n<h6 id=\"Floyd-Warshall%E7%AE%97%E6%B3%95\">Floyd-Warshall\u7b97\u6cd5&#xff08;\u591a\u6e90&#xff09;<\/h6>\n<h6>\u7b97\u6cd5\u601d\u60f3<\/h6>\n<p>Floyd-Warshall\u7b97\u6cd5\u91c7\u7528\u52a8\u6001\u89c4\u5212\u7684\u601d\u60f3&#xff0c;\u901a\u8fc7\u4e09\u91cd\u5faa\u73af\u904d\u5386\u56fe\u4e2d\u7684\u6bcf\u4e2a\u9876\u70b9&#xff0c;\u5e76\u5c1d\u8bd5\u5c06\u5176\u4f5c\u4e3a\u4e2d\u95f4\u70b9\u6765\u66f4\u65b0\u4efb\u610f\u4e24\u4e2a\u9876\u70b9\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u3002\u7b97\u6cd5\u7684\u6838\u5fc3\u5728\u4e8e\u4e0d\u65ad\u6bd4\u8f83\u548c\u66f4\u65b0\u8def\u5f84\u957f\u5ea6&#xff0c;\u76f4\u5230\u627e\u5230\u6240\u6709\u9876\u70b9\u5bf9\u4e4b\u95f4\u7684\u6700\u77ed\u8def\u5f84\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"213\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c0c3f41.png\" width=\"526\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"218\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101736-699ad7c0d988f.png\" width=\"589\" \/><\/p>\n<h6>\u7b97\u6cd5\u6b65\u9aa4<\/h6>\n<p>1.\u521d\u59cb\u5316&#xff1a; \u4f7f\u7528\u56fe\u7684\u5e26\u6743\u90bb\u63a5\u77e9\u9635A\u4f5c\u4e3a\u8d77\u70b9&#xff0c;\u5176\u4e2dA[i][j]\u8868\u793a\u9876\u70b9i\u5230\u9876\u70b9j\u7684\u76f4\u63a5\u8ddd\u79bb\u3002\u5982\u679ci\u548cj\u4e4b\u95f4\u6ca1\u6709\u76f4\u63a5\u8fde\u63a5&#xff0c;\u5219A[i][j]\u88ab\u8bbe\u7f6e\u4e3a\u65e0\u7a77\u5927&#xff08;\u6216\u4e00\u4e2a\u8db3\u591f\u5927\u7684\u6570&#xff09;\u3002 2.\u4e09\u91cd\u5faa\u73af&#xff1a; \u5916\u5c42\u5faa\u73af\u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u4e2d\u95f4\u70b9k&#xff08;1\u5230n&#xff09;\u3002 \u4e2d\u95f4\u4e24\u5c42\u5faa\u73af\u5206\u522b\u904d\u5386\u6240\u6709\u8d77\u70b9i\u548c\u7ec8\u70b9j&#xff08;1\u5230n&#xff09;\u3002 \u5728\u6bcf\u6b21\u8fed\u4ee3\u4e2d&#xff0c;\u68c0\u67e5\u662f\u5426\u53ef\u4ee5\u901a\u8fc7\u9876\u70b9k\u6765\u7f29\u77ed\u4ecei\u5230j\u7684\u8def\u5f84\u957f\u5ea6\u3002\u5982\u679c\u53ef\u4ee5&#xff0c;\u5219\u66f4\u65b0A[i][j]\u4e3aA[i][k] &#043; A[k][j]\u3002 3.\u7ed3\u675f&#xff1a; \u5f53\u6240\u6709\u9876\u70b9\u90fd\u88ab\u7528\u4f5c\u4e2d\u95f4\u70b9\u65f6&#xff0c;\u7b97\u6cd5\u7ed3\u675f\u3002\u6b64\u65f6&#xff0c;A\u77e9\u9635\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20A[i][j]\u90fd\u8868\u793a\u4ece\u9876\u70b9i\u5230\u9876\u70b9j\u7684\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u3002<\/p>\n<p>\u4e3a\u4e86\u8bb0\u5f55\u4e0b\u6700\u77ed\u8def\u5f84\u7684\u6574\u6761\u8def\u5f84\u662f\u600e\u6837\u7684&#xff0c;\u4f7f\u7528\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4pPath[]\u6765\u6807\u8bb0\u6bcf\u4e2a\u70b9\u5728\u6700\u77ed\u8def\u5f84\u4e2d\u524d\u4e00\u4e2a\u8282\u70b9\u662f\u4ec0\u4e48&#xff0c;\u8fd9\u6837\u5c31\u80fd\u591f\u77e5\u9053\u6700\u77ed\u8def\u5f84\u7684\u6574\u6761\u8def\u5f84\u662f\u600e\u6837\u7684\u4e86&#xff08;\u5e76\u67e5\u96c6\u601d\u60f3&#xff09;\u3002\u00a0<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6\u8f83\u9ad8&#xff0c;\u4e3aO(n^3)&#xff0c;\u4e0d\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u56fe\u3002<\/p>\n<h6>\u4ee3\u7801\u5b9e\u73b0<\/h6>\n<p>public void floydWarShall(int[][] dist,int[][] pPath) {<br \/>\n    int n &#061; arrayV.length;<\/p>\n<p>    for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n        Arrays.fill(dist[i],Constant.MAX);<br \/>\n        Arrays.fill(pPath[i],-1);<br \/>\n    }<\/p>\n<p>    for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n        for (int j &#061; 0; j &lt; n; j&#043;&#043;) {<br \/>\n            if(matrix[i][j] !&#061; Constant.MAX) {<br \/>\n                dist[i][j] &#061; matrix[i][j];<br \/>\n                pPath[i][j] &#061; i;<br \/>\n            }else {<br \/>\n                pPath[i][j] &#061; -1;<br \/>\n            }<br \/>\n            if(i &#061;&#061; j) {<br \/>\n                dist[i][j] &#061; 0;<br \/>\n                pPath[i][j] &#061; -1;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    for (int k &#061; 0; k &lt; n; k&#043;&#043;) {<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            for (int j &#061; 0; j &lt; n; j&#043;&#043;) {<br \/>\n                if(dist[i][k] !&#061; Constant.MAX &amp;&amp;<br \/>\n                        dist[k][j] !&#061; Constant.MAX &amp;&amp;<br \/>\n                        dist[i][k] &#043; dist[k][j] &lt; dist[i][j]) {<br \/>\n                    dist[i][j] &#061; dist[i][k] &#043; dist[k][j];<br \/>\n                    \/\/\u66f4\u65b0\u7236\u8282\u70b9\u4e0b\u6807<br \/>\n                    \/\/pPath[i][j] &#061; k;\/\/\u4e0d\u5bf9<br \/>\n                    \/\/\u5982\u679c\u7ecf\u8fc7\u4e86 i-&gt;k  k-&gt;j  \u6b64\u65f6\u662fk<br \/>\n                    \/\/i-&gt;x-&gt;s-&gt;k   k-&gt;..t-&gt;&#8230;x-&gt;j<br \/>\n                    pPath[i][j] &#061; pPath[k][j];<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/ \u6d4b\u8bd5 \u6253\u5370\u6743\u503c\u548c\u8def\u5f84\u77e9\u9635\u89c2\u5bdf\u6570\u636e<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            for (int j &#061; 0; j &lt; n; j&#043;&#043;) {<br \/>\n                if(dist[i][j] &#061;&#061; Constant.MAX) {<br \/>\n                    System.out.print(&#034; * &#034;);<br \/>\n                }else{<br \/>\n                    System.out.print(dist[i][j]&#043;&#034; &#034;);<br \/>\n                }<br \/>\n            }<br \/>\n            System.out.println();<br \/>\n        }<br \/>\n        System.out.println(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;\u6253\u5370\u8def\u5f84&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#034;);<br \/>\n        for (int i &#061; 0; i &lt; n; i&#043;&#043;) {<br \/>\n            for (int j &#061; 0; j &lt; n; j&#043;&#043;) {<br \/>\n                System.out.print(pPath[i][j]&#043;&#034; &#034;);<br \/>\n            }<br \/>\n            System.out.println();<br \/>\n        }<br \/>\n        System.out.println(&#034;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h6>\u4ee3\u7801\u6d4b\u8bd5<\/h6>\n<p>public static void testGraphFloydWarShall() {<br \/>\n    String str &#061; &#034;12345&#034;;<br \/>\n    char[] array &#061; str.toCharArray();<br \/>\n    GraphByMatrix g &#061; new GraphByMatrix(str.length(),true);<br \/>\n    g.initArrayV(array);<br \/>\n    g.addEdge(&#039;1&#039;, &#039;2&#039;, 3);<br \/>\n    g.addEdge(&#039;1&#039;, &#039;3&#039;, 8);<br \/>\n    g.addEdge(&#039;1&#039;, &#039;5&#039;, -4);<br \/>\n    g.addEdge(&#039;2&#039;, &#039;4&#039;, 1);<br \/>\n    g.addEdge(&#039;2&#039;, &#039;5&#039;, 7);<br \/>\n    g.addEdge(&#039;3&#039;, &#039;2&#039;, 4);<br \/>\n    g.addEdge(&#039;4&#039;, &#039;1&#039;, 2);<br \/>\n    g.addEdge(&#039;4&#039;, &#039;3&#039;, -5);<br \/>\n    g.addEdge(&#039;5&#039;, &#039;4&#039;, 6);<\/p>\n<p>    int[][] dist &#061; new int[array.length][array.length];<br \/>\n    int[][] parentPath &#061; new int[array.length][array.length];<br \/>\n    g.floydWarShall(dist,parentPath);<\/p>\n<p>    for (int i &#061; 0; i &lt; array.length; i&#043;&#043;) {<br \/>\n        g.printShortPath(array[i],dist[i],parentPath[i]);<br \/>\n        System.out.println(&#034;************************&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"746\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101737-699ad7c106d0a.png\" width=\"1159\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55<br \/>\n\u200b\u7f16\u8f91<br \/>\n\u6700\u77ed\u8def\u5f84<br \/>\nDijkstra\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09;<br \/>\n\u7b97\u6cd5\u601d\u60f3<br \/>\n\u7b97\u6cd5\u6b65\u9aa4<br \/>\n\u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5<br \/>\n\u7f3a\u70b9<br \/>\nBellman-Ford\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09;<br \/>\n\u7b97\u6cd5\u601d\u60f3<br \/>\n\u7b97\u6cd5\u6b65\u9aa4<br \/>\n\u4ee3\u7801\u5b9e\u73b0<br \/>\n\u4ee3\u7801\u6d4b\u8bd5<br \/>\nFloyd-Warshall\u7b97\u6cd5&#xff08;\u591a\u6e90&#xff09;<br \/>\n\u7b97\u6cd5\u601d\u60f3<br \/>\n\u7b97\u6cd5\u6b65\u9aa4<br \/>\n\u4ee3\u7801\u5b9e\u73b0<br \/>\n\u4ee3\u7801\u6d4b\u8bd5 \u6700\u77ed\u8def\u5f84<br \/>\n\u6700\u77ed\u8def\u5f84\u95ee\u9898&#xff1a;\u4ece\u5728\u5e26\u6743\u56fe\u7684\u67d0\u4e00\u9876\u70b9\u51fa\u53d1&#xff0c;\u627e\u51fa\u4e00\u6761\u901a\u5f80\u53e6\u4e00\u9876\u70b9\u7684<\/p>\n","protected":false},"author":2,"featured_media":76527,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99],"topic":[],"class_list":["post-76540","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8be6\u89e3\u6700\u77ed\u8def\u5f84 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/76540.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8be6\u89e3\u6700\u77ed\u8def\u5f84 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u200b\u7f16\u8f91 \u6700\u77ed\u8def\u5f84 Dijkstra\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09; \u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u6b65\u9aa4 \u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5 \u7f3a\u70b9 Bellman-Ford\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09; \u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u6b65\u9aa4 \u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5 Floyd-Warshall\u7b97\u6cd5&#xff08;\u591a\u6e90&#xff09; \u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u6b65\u9aa4 \u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5 \u6700\u77ed\u8def\u5f84 \u6700\u77ed\u8def\u5f84\u95ee\u9898&#xff1a;\u4ece\u5728\u5e26\u6743\u56fe\u7684\u67d0\u4e00\u9876\u70b9\u51fa\u53d1&#xff0c;\u627e\u51fa\u4e00\u6761\u901a\u5f80\u53e6\u4e00\u9876\u70b9\u7684\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76540.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-22T10:17:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101735-699ad7bf3de03.gif\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76540.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76540.html\",\"name\":\"\u8be6\u89e3\u6700\u77ed\u8def\u5f84 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-22T10:17:38+00:00\",\"dateModified\":\"2026-02-22T10:17:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76540.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76540.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76540.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8be6\u89e3\u6700\u77ed\u8def\u5f84\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8be6\u89e3\u6700\u77ed\u8def\u5f84 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/76540.html","og_locale":"zh_CN","og_type":"article","og_title":"\u8be6\u89e3\u6700\u77ed\u8def\u5f84 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55 \u200b\u7f16\u8f91 \u6700\u77ed\u8def\u5f84 Dijkstra\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09; \u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u6b65\u9aa4 \u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5 \u7f3a\u70b9 Bellman-Ford\u7b97\u6cd5&#xff08;\u5355\u6e90&#xff09; \u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u6b65\u9aa4 \u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5 Floyd-Warshall\u7b97\u6cd5&#xff08;\u591a\u6e90&#xff09; \u7b97\u6cd5\u601d\u60f3 \u7b97\u6cd5\u6b65\u9aa4 \u4ee3\u7801\u5b9e\u73b0 \u4ee3\u7801\u6d4b\u8bd5 \u6700\u77ed\u8def\u5f84 \u6700\u77ed\u8def\u5f84\u95ee\u9898&#xff1a;\u4ece\u5728\u5e26\u6743\u56fe\u7684\u67d0\u4e00\u9876\u70b9\u51fa\u53d1&#xff0c;\u627e\u51fa\u4e00\u6761\u901a\u5f80\u53e6\u4e00\u9876\u70b9\u7684","og_url":"https:\/\/www.wsisp.com\/helps\/76540.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-22T10:17:38+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260222101735-699ad7bf3de03.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76540.html","url":"https:\/\/www.wsisp.com\/helps\/76540.html","name":"\u8be6\u89e3\u6700\u77ed\u8def\u5f84 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-22T10:17:38+00:00","dateModified":"2026-02-22T10:17:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76540.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76540.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76540.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u8be6\u89e3\u6700\u77ed\u8def\u5f84"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=76540"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76540\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/76527"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76540"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}