{"id":520,"date":"2015-05-07T00:26:57","date_gmt":"2015-05-06T16:26:57","guid":{"rendered":"https:\/\/www.yesybl.com\/?p=520"},"modified":"2015-05-11T12:18:21","modified_gmt":"2015-05-11T04:18:21","slug":"dijkstra%e7%ae%97%e6%b3%95%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.yesybl.com\/?p=520","title":{"rendered":"Dijkstra\u7b97\u6cd5\u8be6\u89e3"},"content":{"rendered":"<p>Dijkstra\u7b97\u6cd5\uff0c\u4e2d\u6587\u7ffb\u8bd1\u4e3a\u8fea\u6770\u65af\u7279\u62c9\u7b97\u6cd5\uff0c\u662f\u5728\u5e26\u6743\u6709\u5411\u56feG = (V, W) \uff08V\u662f\u8282\u70b9\u7684\u96c6\u5408\uff0cW\u662f\u8fb9\u4e0a\u6743\u503c\u7684\u96c6\u5408\uff0c\u5728\u96c6\u5408W\u4e2d\uff0c\u4e0d\u76f4\u63a5\u76f8\u8fde\u7684\u8282\u70b9\u95f4\u7684\u8ddd\u79bb\u6807\u8bb0\u4e3a\u65e0\u7a77\u5927\uff09\u4e2d\u6c42\u67d0\u4e2a\u8282\u70b9\u5230\u5176\u4f59\u8282\u70b9\u4e4b\u95f4\u6700\u77ed\u8def\u5f84\u7684\u7ecf\u5178\u7b97\u6cd5\u3002\u8be5\u7b97\u6cd5\u7684\u6838\u5fc3\u601d\u60f3\u662f\u5c06\u56fe\u4e2d\u6240\u6709\u7684\u8282\u70b9\u5212\u5206\u4e3a2\u4e2a\u96c6\u5408\uff0c\u96c6\u5408S\u5305\u542b\u5df2\u7ecf\u627e\u5230\u6700\u77ed\u8def\u5f84\u7684\u8282\u70b9\uff0c\u96c6\u5408U\u5305\u542b\u5c1a\u672a\u627e\u5230\u6700\u77ed\u8def\u5f84\u7684\u8282\u70b9\u7684\u8ddd\u79bb\uff08\u521d\u59cb\u503c\u5168\u90e8\u8bbe\u5b9a\u4e3a\u65e0\u7a77\u5927\uff09\u3002\u4ece\u67d0\u4e00\u70b9v\u5f00\u59cb\u91c7\u7528\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u601d\u60f3\u5bf9\u56fe\u8fdb\u884c\u904d\u5386\uff0c\u6bcf\u627e\u5230\u4e00\u4e2a\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84\uff0c\u5c31\u5c06\u8be5\u8282\u70b9\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\uff0c\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\uff0c\u76f4\u5230\u6700\u540eU\u53d8\u4e3a\u7a7a\u96c6\uff0cS\u5305\u542b\u56fe\u4e2d\u6240\u6709\u7684\u8282\u70b9\u5230\u51fa\u53d1\u70b9\u7684\u6700\u5c0f\u8ddd\u79bb\u3002\u5728\u52a0\u5165\u7684\u8fc7\u7a0b\u4e2d\uff0c\u603b\u4fdd\u6301\u4ece\u6e90\u70b9v\u5230S\u4e2d\u5404\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e0d\u5927\u4e8e\u4ece\u6e90\u70b9v\u5230U\u4e2d\u4efb\u4f55\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u957f<span style=\"font-family:\u5b8b\u4f53\">\u5ea6\u3002<\/span>\n\t<\/p>\n<p>Dijkstra\u7b97\u6cd5\u7684\u8fc7\u7a0b\uff1a\n<\/p>\n<ol>\n<li>\u9009\u53d6\u67d0\u4e2a\u8282\u70b9v\u4f5c\u4e3a\u51fa\u53d1\u70b9\uff0c\u4ece\u51fa\u53d1\u70b9\u5230\u51fa\u53d1\u70b9\u8ddd\u79bb\u4e3a0\uff0c\u5373\u627e\u5230\u6700\u5c0f\u8def\u5f84\u3002\u5c06\u8be5\u51fa\u53d1\u70b9\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\u3002\n<\/li>\n<li>\u5728\u96c6\u5408W\u4e2d\u67e5\u770b\u51fa\u53d1\u70b9v\u5230\u96c6\u5408U\u4e2d\u5404\u4e2a\u8282\u70b9\u7684\u8ddd\u79bb\u3002\u627e\u51fa\u8ddd\u79bb\u6700\u5c0f\u7684\u8282\u70b9k\uff08\u5230k\u7684\u6700\u77ed\u8def\u5f84\u627e\u5230\uff09\uff0c\u5c06k\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\u3002\n<\/li>\n<li>\u4ee5k\u4f5c\u4e3a\u4e2d\u95f4\u70b9\uff0c\u5728W\u4e2d\u67e5\u770b\u4ecek\u5230U\u4e2d\u8282\u70b9m\u7684\u8ddd\u79bb\uff0c\u5982\u679cm\u5728W\u4e2d\u7684\u503c\u5c0f\u4e8em\u5728U\u4e2d\u7684\u503c\uff08k\u548cm\u76f4\u63a5\u8fde\u63a5\uff09\uff0c\u5c06m\u5728W\u4e2d\u7684\u503c\u4e0ek\u5728U\u4e2d\u7684\u503c\u76f8\u52a0\uff08\u4ecev\u51fa\u53d1\u7ecf\u8fc7k\u5230\u8fbem\u7684\u8ddd\u79bb\uff09\uff0c\u518d\u5c06\u76f8\u52a0\u7ed3\u679c\u4e0eW\u4e2dv\u5230m\u7684\u503c(v\u4e0d\u7ecf\u8fc7\u4e2d\u95f4\u70b9\u5230m\u7684\u8ddd\u79bb)\u5bf9\u6bd4\u5927\u5c0f\uff0c\u9009\u53d6\u8f83\u5c0f\u7684\u503c\u8ddf\u65b0k\u5728U\u4e2d\u7684\u6570\u636e\u3002\n<\/li>\n<li>\u5728U\u4e2d\u627e\u51fa\u6570\u503c\u6700\u5c0f\u7684\u8282\u70b9n\uff0c\u8be5\u503c\u5373\u4e3av\u5230n\u7684\u6700\u77ed\u8def\u5f84\u3002\u5c06n\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\u3002\u628an\u4f5c\u4e3a\u4e2d\u95f4\u70b9\u91cd\u590d\u7b2c3\u30014\u6b65\uff0c\u76f4\u5230U\u4e2d\u6240\u6709\u7684\u8282\u70b9\u90fd\u79fb\u52a8\u5230S\u4e2d\u3002\n<\/li>\n<\/ol>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/www.yesybl.com\/wp-content\/uploads\/2015\/05\/050615_1629_Dijkstar1.png\" alt=\"\"\/>\n\t<\/p>\n<p style=\"text-align: center\">\u56fe1\n<\/p>\n<p>Dijkstra\u7b97\u6cd5\u7684\u624b\u7b97\u65b9\u6cd5\n<\/p>\n<p>\u5982\u56fe1\uff0c\u4ece\u8282\u70b9A\u5f00\u59cb\u3002\u9996\u5148\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u8868\uff0c\u7528\u8be5\u8868\u8bb0\u5f55\u6bcf\u6b21\u8fd0\u7b97\u7684\u503c\u3002\u8be5\u8868\u8868\u5934\u4ee3\u8868\u4e86\u96c6\u5408U\u4e2d\u5305\u542b\u7684\u8282\u70b9\uff08\u672a\u627e\u51fa\u6700\u77ed\u8def\u5f84\u8282\u70b9\uff1aA\u3001B\u3001C\u3001D\uff09\u3002\u7b2c\uff12\u884c\u5c06\u5404\u8282\u70b9\u7684\u8ddd\u79bb\uff0c\u521d\u59cb\u5316\u4e3a\u65e0\u7a77\u5927\uff0c\u7528INF\u8868\u793a\u3002<\/p>\n<div style=\"text-align: center\">\n<table style=\"border-collapse:collapse\" border=\"0\">\n<colgroup>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/><\/colgroup>\n<tbody valign=\"top\">\n<tr>\n<td style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\u00a0<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">A<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">D<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\u00a0<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\n\u00a0<\/p>\n<p>\u70b9A\u662f\u51fa\u53d1\u70b9\uff0c\u81ea\u8eab\u5230\u81ea\u8eab\u7684\u8def\u5f84\u6700\u77ed\uff0c\u4e3a0\uff0c\u5373A\u5230\uff21\u7684\u6700\u77ed\u8def\u5f84\u627e\u5230\u3002\u5728\uff21\u5217\u7684\u7b2c\uff12\u884c\u8f93\u5165\uff10\uff0c\u5e76\u7528\u4e0b\u5212\u7ebf\u6807\u51fa\uff0c\u8868\u660e\u5c06\uff21\u4ece\uff35\u4e2d\u79fb\u9664\u3002\u5728\u8868\u7684\u7b2c\uff12\u884c\u6700\u5de6\u4fa7\u5199A\uff0c\u8868\u793a\u5c06A\u52a0\u5165\u96c6\u5408S\u3002<\/p>\n<div style=\"text-align: center\">\n<table style=\"border-collapse:collapse\" border=\"0\">\n<colgroup>\n<col style=\"width:146px\"\/>\n<col style=\"width:146px\"\/>\n<col style=\"width:149px\"\/>\n<col style=\"width:149px\"\/>\n<col style=\"width:149px\"\/><\/colgroup>\n<tbody valign=\"top\">\n<tr>\n<td style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\u00a0<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">A\u00a0<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">D<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">A\u00a0<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u5efa\u7acb\u8868\u683c\u7b2c3\u884c\u3002\u6b64\u65f6\u96c6\u5408U\u4e2d\u5305\u542b{B\u3001C\u3001D}\uff0c\u7531\u56fe\u53ef\u77e5A-&gt;B\u7684\u8ddd\u79bb\u4e3a1\uff08\u67e5\u8be2\u96c6\u5408W\uff09\uff0c\u66f4\u65b0B\u5217\u7684\u6570\u503c\uff0c\u5199\u5165\u7b2c3\u884c\u3002\u7531\u56fe\u53ef\u77e5A-&gt;C\u7684\u8ddd\u79bb\u4e3a5\uff0c\u66f4\u65b0B\u5217\u7684\u6570\u503c\uff0c\u5199\u5165\u7b2c3\u884c\u3002\u7531\u56fe\u53ef\u77e5A-&gt;D\u4e0d\u53ef\u76f4\u8fbe\uff0c\u6807\u8bb0\u4e3aINF\u3002\u5728\u8868\u7b2c3\u884c\u4e2d\u5bf9\u96c6\u5408U\u4e2d\u6240\u62e5\u6709\u7684\u5143\u7d20{1\uff0c5\uff0cINF}\u6c42\u6700\u5c0f\u503c\uff0c\u5f97\u5230B\uff0c\u6b64\u65f6B\u5217\u7b2c3\u884c\u6570\u636e\u5373\u4e3aA-&gt;B\u7684\u6700\u5c0f\u8def\u5f84\u3002\u5bf9B\u5217\u7b2c3\u884c\u6570\u636e\u52a0\u4e0b\u5212\u7ebf\u6807\u8bc6\u51fa\uff0c\u5373\u5c06B\u79fb\u51fa\u96c6\u5408U\u3002\u540c\u65f6\u5728\u7b2c3\u884c\u6700\u5de6\u7aef\u5199B\uff0c\u5373\u5c06B\u52a0\u5165\u96c6\u5408S\u4e2d\u3002<\/p>\n<div style=\"text-align: center\">\n<table style=\"border-collapse:collapse\" border=\"0\">\n<colgroup>\n<col style=\"width:146px\"\/>\n<col style=\"width:146px\"\/>\n<col style=\"width:149px\"\/>\n<col style=\"width:149px\"\/>\n<col style=\"width:149px\"\/><\/colgroup>\n<tbody valign=\"top\">\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\u00a0<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">A<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">D<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">A\u00a0<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">B\u00a0<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">1<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">5<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u5efa\u7acb\u8868\u683c\u7b2c4\u884c\u3002\u6b64\u65f6\u96c6\u5408U\u4e2d\u5305\u542b{C\u3001D}\uff0c\u8282\u70b9B\u4e3a\u4e2d\u95f4\u70b9\u3002\u7531\u56fe\u53ef\u77e5B-&gt;C\u7684\u8ddd\u79bb\u4e3a1\uff0c\u800cA-&gt;B\u7684\u8ddd\u79bb\u4fdd\u5b58\u5728\u8868B\u5217\u4e2d\uff0c\u662f1\uff0c\u5219A-&gt;B-&gt;C\u7684\u8ddd\u79bb\u4e3a1+1=2\u3002\u7531\u8868C\u5217\u7b2c3\u884c\u6570\u636e\u53ef\u77e5\u76ee\u524d\u5230\u8fbeC\u7684\u8ddd\u79bb\u4e3a5\uff08A\u76f4\u63a5\u5230\u8fbeC\uff09\u3002\u6c42\u4e24\u6761\u8def\u5f84\u7684\u6700\u5c0f\u503cmin(5,1+1)=2;\u66f4\u65b0C\u5217\u6570\u636e\uff0c\u5c062\u5199\u5165C\u5217\u7b2c4\u884c\u3002\u7531\u56fe\u53ef\u77e5B-&gt;D\u70b9\u7684\u8ddd\u79bb\u4e3a1\uff0c\u5219A-&gt;B-&gt;D\u7684\u8ddd\u79bb\u4e3a1+1=2\uff0c\u800cA-&gt;D\u4e0d\u53ef\u76f4\u63a5\u62b5\u8fbe\uff0c\u6545\u800c\u53d6\u503c\u65e0\u7a77\u5927INF\uff08\u8be5\u503c\u8bb0\u5f55\u5728\u96c6\u5408W\u4e2d\uff0c\u6b64\u65f6\u8be5\u503c\u7b49\u4e8e\u8868\u4e2dD\u5217\u6570\u636e\uff09\u3002\u6c42\u4e24\u6761\u8def\u5f84\u7684\u6700\u5c0f\u503cmin(INF\uff0c1+1)=2\u3002\u66f4\u884cD\u5217\u6570\u636e\uff0c\u5c062\u5199\u5165\u5230D\u5217\u7b2c4\u884c\u3002\u5bf9\u96c6\u5408U\u4e2d\u7684\u6570\u636e\u53d6\u6700\u5c0f\u503c\uff0cC\u548cD\u5747\u4e3a2\uff0c\u4efb\u9009\u4e00\u4e2a\uff0c\u8be5\u8282\u70b9\u5230A\u7684\u6700\u77ed\u8ddd\u79bb\u5373\u88ab\u8ba1\u7b97\u51fa\u6765\u3002\u6bd4\u5982\u9009C\u3002\u5bf9C\u8fdb\u884c\u6807\u8bb0\u3002<\/p>\n<div style=\"text-align: center\">\n<table style=\"border-collapse:collapse\" border=\"0\">\n<colgroup>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/><\/colgroup>\n<tbody valign=\"top\">\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\u00a0<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">A<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">D<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">A<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">1<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">5<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">1<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">2<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">2<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u91cd\u590d\u4e0a\u9762\u7684\u64cd\u4f5c\uff0c\u5efa\u7acb\u8868\u683c\u7b2c5\u884c\u3002\u6b64\u65f6\u96c6\u5408U\u4e2d\u53ea\u5305\u542b{D}\uff0c\u8282\u70b9C\u4e3a\u4e2d\u95f4\u70b9\u3002\u7531\u56fe\u53ef\u77e5C-&gt;D\u7684\u8ddd\u79bb\u4e3a1\u3002\u800cA-&gt;C\u7684\u6700\u77ed\u8ddd\u79bb\u5df2\u7ecf\u6c42\u51fa\uff0c\u5728\u4e0a\u8868\u4e2dC\u5217\u7b2c4\u884c\uff0c\u4e3a2\uff08\u7ecf\u8fc7\u8282\u70b9B\uff09\u3002\u6545A-&gt;B-&gt;C-&gt;D\u7684\u8ddd\u79bb\u4e3a2+1=3\u3002\u8868\u4e2dD\u5217\u7b2c4\u884c\u8bb0\u5f55\u5230\u8fbeD\u70b9\u7684\u6700\u5c0f\u8def\u5f84\u4e3a2\uff08\u901a\u8fc7B\u70b9\uff09\uff0c\u6c42\u4e24\u6761\u8def\u5f84\u7684\u6700\u5c0f\u503cmin(2,2+1)=2\u3002\u5373D\u70b9\u7684\u6700\u5c0f\u8def\u5f84\u4e3a2\uff0c\u5c062\u5199\u5165D\u5217\u7b2c5\u884c\u5e76\u5bf9D\u5217\u7b2c5\u884c\u8fdb\u884c\u6807\u8bb0\u3002\u6b64\u65f6\u96c6\u5408U\u4e3a\u7a7a\u96c6\uff0c\u96c6\u5408S\u4e2d\u7684\u5143\u7d20\u4e3a{A\u3001B\u3001C\u3001D}\uff0c\u8ba1\u7b97\u5b8c\u6bd5\u3002\u8868\u4e2d\u7b2c5\u884c\u6240\u8bb0\u5f55\u6570\u636e\u5373\u4e3aA\u70b9\u5230\u5404\u70b9\u7684\u6700\u5c0f\u8def\u5f84\u503c\u3002<\/p>\n<div style=\"text-align: center\">\n<table style=\"border-collapse:collapse\" border=\"0\">\n<colgroup>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/>\n<col style=\"width:148px\"\/><\/colgroup>\n<tbody valign=\"top\">\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\u00a0<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">A<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">D<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">A<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">B<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">1<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">5<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">INF<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">C<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">1<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">2<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\">2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  none; border-right:  solid 0.5pt\">\n<p style=\"text-align: right\">D<\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">0<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">1<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">2<\/span><\/p>\n<\/td>\n<td vAlign=\"middle\" style=\"padding-left: 9px; padding-right: 9px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt\">\n<p style=\"text-align: center\"><span style=\"text-decoration:underline\">2<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\n\u00a0<\/p>\n<p>\u5177\u4f53\u8def\u5f84\uff08\u7ecf\u8fc7\u7684\u8282\u70b9\uff09\u53ef\u4ee5\u901a\u8fc7\u56de\u6eaf\u6cd5\u6c42\u51fa\u3002\u5728\u6700\u540e\u4e00\u5f20\u8868\u4e2d\u627e\u5230\u8981\u6c42\u70b9\u6240\u5728\u7684\u5217\uff0c\u4ece\u4e0b\u5411\u4e0a\u56de\u6eaf\uff0c\u5f53\u6570\u503c\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u8df3\u8f6c\u5230\u6240\u5728\u884c\u6240\u5bf9\u5e94\u7684S\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u6240\u5728\u7684\u5217\uff0c\u8bb0\u5f55\u4e0b\u8be5\u70b9\uff0c\u7136\u540e\u7ee7\u7eed\u56de\u6eaf\uff0c\u76f4\u5230\u5230\u8fbe\u51fa\u53d1\u70b9\u3002\n<\/p>\n<p>\u5982\u6c42\u5230\u8fbe<span style=\"color:red\">C<\/span>\u70b9\u7684\u5177\u4f53\u8def\u5f84\uff0c\u4eceC\u5217\u7b2c5\u884c\u5411\u4e0a\u56de\u6eaf\uff0c\u5230\u8fbe\u7b2c3\u884c\u65f6\u6570\u503c\u53d1\u751f\u53d8\u5316\uff0c\u7b2c3\u884c\u5bf9\u5e94\u4e3aS\u96c6\u5408\u4e2d\u7684<span style=\"color:red\">B<\/span>\uff0c\u5219\u4eceB\u5217\u7b2c3\u884c\u5411\u4e0a\u56de\u6eaf\uff0c\u5230\u8fbeB\u5217\u7b2c2\u884c\uff0c\u6570\u503c\u53d1\u751f\u53d8\u5316\uff0c\u7b2c2\u884c\u6240\u5bf9\u5e94\u7684\u96c6\u5408S\u4e2d\u7684\u5143\u7d20\u4e3a<span style=\"color:red\">A<\/span>\uff0c\u662f\u8d77\u70b9\uff0c\u56de\u6eaf\u5b8c\u6210\u3002\u5177\u4f53\u8def\u5f84\u5373\u4e3aA-&gt;B-&gt;C\u3002\n<\/p>\n<p>\u672c\u601d\u8def\u6240\u5bf9\u5e94\u7684C#\u6e90\u4ee3\u7801\u8bf7\u53c2\u770b\u300a<a href=\"https:\/\/www.yesybl.com\/?p=516\">Dijkstra\u7b97\u6cd5C#\u6f14\u793a\u7a0b\u5e8f<\/a>\u300b\u4e00\u6587\u3002<\/p>\n<\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<a href=\"https:\/\/www.yesybl.com\/?p=520\" rel=\"bookmark\" title=\"Permalink to Dijkstra\u7b97\u6cd5\u8be6\u89e3\"><p>Dijkstra\u7b97\u6cd5\uff0c\u4e2d\u6587\u7ffb\u8bd1\u4e3a\u8fea\u6770\u65af\u7279\u62c9\u7b97\u6cd5\uff0c\u662f\u5728\u5e26\u6743\u6709\u5411\u56feG = (V, W) \uff08V\u662f\u8282\u70b9\u7684\u96c6\u5408\uff0cW\u662f\u8fb9\u4e0a\u6743\u503c\u7684\u96c6\u5408\uff0c\u5728\u96c6\u5408W\u4e2d\uff0c\u4e0d\u76f4\u63a5\u76f8\u8fde\u7684\u8282\u70b9\u95f4\u7684\u8ddd\u79bb\u6807\u8bb0\u4e3a\u65e0\u7a77\u5927\uff09\u4e2d\u6c42\u67d0\u4e2a\u8282\u70b9\u5230\u5176\u4f59\u8282\u70b9\u4e4b\u95f4\u6700\u77ed\u8def\u5f84\u7684\u7ecf\u5178\u7b97\u6cd5\u3002\u8be5\u7b97\u6cd5\u7684\u6838\u5fc3\u601d\u60f3\u662f\u5c06\u56fe\u4e2d\u6240\u6709\u7684\u8282\u70b9\u5212\u5206\u4e3a2\u4e2a\u96c6\u5408\uff0c\u96c6\u5408S\u5305\u542b\u5df2\u7ecf\u627e\u5230\u6700\u77ed\u8def\u5f84\u7684\u8282\u70b9\uff0c\u96c6\u5408U\u5305\u542b\u5c1a\u672a\u627e\u5230\u6700\u77ed\u8def\u5f84\u7684\u8282\u70b9\u7684\u8ddd\u79bb\uff08\u521d\u59cb\u503c\u5168\u90e8\u8bbe\u5b9a\u4e3a\u65e0\u7a77\u5927\uff09\u3002\u4ece\u67d0\u4e00\u70b9v\u5f00\u59cb\u91c7\u7528\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u601d\u60f3\u5bf9\u56fe\u8fdb\u884c\u904d\u5386\uff0c\u6bcf\u627e\u5230\u4e00\u4e2a\u8282\u70b9\u7684\u6700\u77ed\u8def\u5f84\uff0c\u5c31\u5c06\u8be5\u8282\u70b9\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\uff0c\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\uff0c\u76f4\u5230\u6700\u540eU\u53d8\u4e3a\u7a7a\u96c6\uff0cS\u5305\u542b\u56fe\u4e2d\u6240\u6709\u7684\u8282\u70b9\u5230\u51fa\u53d1\u70b9\u7684\u6700\u5c0f\u8ddd\u79bb\u3002\u5728\u52a0\u5165\u7684\u8fc7\u7a0b\u4e2d\uff0c\u603b\u4fdd\u6301\u4ece\u6e90\u70b9v\u5230S\u4e2d\u5404\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u4e0d\u5927\u4e8e\u4ece\u6e90\u70b9v\u5230U\u4e2d\u4efb\u4f55\u9876\u70b9\u7684\u6700\u77ed\u8def\u5f84\u957f\u5ea6\u3002 Dijkstra\u7b97\u6cd5\u7684\u8fc7\u7a0b\uff1a \u9009\u53d6\u67d0\u4e2a\u8282\u70b9v\u4f5c\u4e3a\u51fa\u53d1\u70b9\uff0c\u4ece\u51fa\u53d1\u70b9\u5230\u51fa\u53d1\u70b9\u8ddd\u79bb\u4e3a0\uff0c\u5373\u627e\u5230\u6700\u5c0f\u8def\u5f84\u3002\u5c06\u8be5\u51fa\u53d1\u70b9\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\u3002 \u5728\u96c6\u5408W\u4e2d\u67e5\u770b\u51fa\u53d1\u70b9v\u5230\u96c6\u5408U\u4e2d\u5404\u4e2a\u8282\u70b9\u7684\u8ddd\u79bb\u3002\u627e\u51fa\u8ddd\u79bb\u6700\u5c0f\u7684\u8282\u70b9k\uff08\u5230k\u7684\u6700\u77ed\u8def\u5f84\u627e\u5230\uff09\uff0c\u5c06k\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\u3002 \u4ee5k\u4f5c\u4e3a\u4e2d\u95f4\u70b9\uff0c\u5728W\u4e2d\u67e5\u770b\u4ecek\u5230U\u4e2d\u8282\u70b9m\u7684\u8ddd\u79bb\uff0c\u5982\u679cm\u5728W\u4e2d\u7684\u503c\u5c0f\u4e8em\u5728U\u4e2d\u7684\u503c\uff08k\u548cm\u76f4\u63a5\u8fde\u63a5\uff09\uff0c\u5c06m\u5728W\u4e2d\u7684\u503c\u4e0ek\u5728U\u4e2d\u7684\u503c\u76f8\u52a0\uff08\u4ecev\u51fa\u53d1\u7ecf\u8fc7k\u5230\u8fbem\u7684\u8ddd\u79bb\uff09\uff0c\u518d\u5c06\u76f8\u52a0\u7ed3\u679c\u4e0eW\u4e2dv\u5230m\u7684\u503c(v\u4e0d\u7ecf\u8fc7\u4e2d\u95f4\u70b9\u5230m\u7684\u8ddd\u79bb)\u5bf9\u6bd4\u5927\u5c0f\uff0c\u9009\u53d6\u8f83\u5c0f\u7684\u503c\u8ddf\u65b0k\u5728U\u4e2d\u7684\u6570\u636e\u3002 \u5728U\u4e2d\u627e\u51fa\u6570\u503c\u6700\u5c0f\u7684\u8282\u70b9n\uff0c\u8be5\u503c\u5373\u4e3av\u5230n\u7684\u6700\u77ed\u8def\u5f84\u3002\u5c06n\u4ece\u96c6\u5408U\u4e2d\u79fb\u9664\u5e76\u52a0\u5165\u5230\u96c6\u5408S\u4e2d\u3002\u628an\u4f5c\u4e3a\u4e2d\u95f4\u70b9\u91cd\u590d\u7b2c3\u30014\u6b65\uff0c\u76f4\u5230U\u4e2d\u6240\u6709\u7684\u8282\u70b9\u90fd\u79fb\u52a8\u5230S\u4e2d\u3002 \u56fe1 Dijkstra\u7b97\u6cd5\u7684\u624b\u7b97\u65b9\u6cd5 \u5982\u56fe1\uff0c\u4ece\u8282\u70b9A\u5f00\u59cb\u3002\u9996\u5148\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u8868\uff0c\u7528\u8be5\u8868\u8bb0\u5f55\u6bcf\u6b21\u8fd0\u7b97\u7684\u503c\u3002\u8be5\u8868\u8868\u5934\u4ee3\u8868\u4e86\u96c6\u5408U\u4e2d\u5305\u542b\u7684\u8282\u70b9\uff08\u672a\u627e\u51fa\u6700\u77ed\u8def\u5f84\u8282\u70b9\uff1aA\u3001B\u3001C\u3001D\uff09\u3002\u7b2c\uff12\u884c\u5c06\u5404\u8282\u70b9\u7684\u8ddd\u79bb\uff0c\u521d\u59cb\u5316\u4e3a\u65e0\u7a77\u5927\uff0c\u7528INF\u8868\u793a\u3002 \u00a0 A B C D \u00a0 INF INF INF INF \u00a0 \u70b9A\u662f\u51fa\u53d1\u70b9\uff0c\u81ea\u8eab\u5230\u81ea\u8eab\u7684\u8def\u5f84\u6700\u77ed\uff0c\u4e3a0\uff0c\u5373A\u5230\uff21\u7684\u6700\u77ed\u8def\u5f84\u627e\u5230\u3002\u5728\uff21\u5217\u7684\u7b2c\uff12\u884c\u8f93\u5165\uff10\uff0c\u5e76\u7528\u4e0b\u5212\u7ebf\u6807\u51fa\uff0c\u8868\u660e\u5c06\uff21\u4ece\uff35\u4e2d\u79fb\u9664\u3002\u5728\u8868\u7684\u7b2c\uff12\u884c\u6700\u5de6\u4fa7\u5199A\uff0c\u8868\u793a\u5c06A\u52a0\u5165\u96c6\u5408S\u3002 \u00a0 A\u00a0 B C D A\u00a0 0 INF INF INF \u5efa\u7acb\u8868\u683c\u7b2c3\u884c\u3002\u6b64\u65f6\u96c6\u5408U\u4e2d\u5305\u542b{B\u3001C\u3001D}\uff0c\u7531\u56fe\u53ef\u77e5A-&gt;B\u7684\u8ddd\u79bb\u4e3a1\uff08\u67e5\u8be2\u96c6\u5408W\uff09\uff0c\u66f4\u65b0B\u5217\u7684\u6570\u503c\uff0c\u5199\u5165\u7b2c3\u884c\u3002\u7531\u56fe\u53ef\u77e5A-&gt;C\u7684\u8ddd\u79bb\u4e3a5\uff0c\u66f4\u65b0B\u5217\u7684\u6570\u503c\uff0c\u5199\u5165\u7b2c3\u884c\u3002\u7531\u56fe\u53ef\u77e5A-&gt;D\u4e0d\u53ef\u76f4\u8fbe\uff0c\u6807\u8bb0\u4e3aINF\u3002\u5728\u8868\u7b2c3\u884c\u4e2d\u5bf9\u96c6\u5408U\u4e2d\u6240\u62e5\u6709\u7684\u5143\u7d20{1\uff0c5\uff0cINF}\u6c42\u6700\u5c0f\u503c\uff0c\u5f97\u5230B\uff0c\u6b64\u65f6B\u5217\u7b2c3\u884c\u6570\u636e\u5373\u4e3aA-&gt;B\u7684\u6700\u5c0f\u8def\u5f84\u3002\u5bf9B\u5217\u7b2c3\u884c\u6570\u636e\u52a0\u4e0b\u5212\u7ebf\u6807\u8bc6\u51fa\uff0c\u5373\u5c06B\u79fb\u51fa\u96c6\u5408U\u3002\u540c\u65f6\u5728\u7b2c3\u884c\u6700\u5de6\u7aef\u5199B\uff0c\u5373\u5c06B\u52a0\u5165\u96c6\u5408S\u4e2d\u3002 \u00a0 A B C D A\u00a0 0 INF INF INF B\u00a0 0 1 5 INF \u5efa\u7acb\u8868\u683c\u7b2c4\u884c\u3002\u6b64\u65f6\u96c6\u5408U\u4e2d\u5305\u542b{C\u3001D}\uff0c\u8282\u70b9B\u4e3a\u4e2d\u95f4\u70b9\u3002\u7531\u56fe\u53ef\u77e5B-&gt;C\u7684\u8ddd\u79bb\u4e3a1\uff0c\u800cA-&gt;B\u7684\u8ddd\u79bb\u4fdd\u5b58\u5728\u8868B\u5217\u4e2d\uff0c\u662f1\uff0c\u5219A-&gt;B-&gt;C\u7684\u8ddd\u79bb\u4e3a1+1=2\u3002\u7531\u8868C\u5217\u7b2c3\u884c\u6570\u636e\u53ef\u77e5\u76ee\u524d\u5230\u8fbeC\u7684\u8ddd\u79bb\u4e3a5\uff08A\u76f4\u63a5\u5230\u8fbeC\uff09\u3002\u6c42\u4e24\u6761\u8def\u5f84\u7684\u6700\u5c0f\u503cmin(5,1+1)=2;\u66f4\u65b0C\u5217\u6570\u636e\uff0c\u5c062\u5199\u5165C\u5217\u7b2c4\u884c\u3002\u7531\u56fe\u53ef\u77e5B-&gt;D\u70b9\u7684\u8ddd\u79bb\u4e3a1\uff0c\u5219A-&gt;B-&gt;D\u7684\u8ddd\u79bb\u4e3a1+1=2\uff0c\u800cA-&gt;D\u4e0d\u53ef\u76f4\u63a5\u62b5\u8fbe\uff0c\u6545\u800c\u53d6\u503c\u65e0\u7a77\u5927INF\uff08\u8be5\u503c\u8bb0\u5f55\u5728\u96c6\u5408W\u4e2d\uff0c\u6b64\u65f6\u8be5\u503c\u7b49\u4e8e\u8868\u4e2dD\u5217\u6570\u636e\uff09\u3002\u6c42\u4e24\u6761\u8def\u5f84\u7684\u6700\u5c0f\u503cmin(INF\uff0c1+1)=2\u3002\u66f4\u884cD\u5217\u6570\u636e\uff0c\u5c062\u5199\u5165\u5230D\u5217\u7b2c4\u884c\u3002\u5bf9\u96c6\u5408U\u4e2d\u7684\u6570\u636e\u53d6\u6700\u5c0f\u503c\uff0cC\u548cD\u5747\u4e3a2\uff0c\u4efb\u9009\u4e00\u4e2a\uff0c\u8be5\u8282\u70b9\u5230A\u7684\u6700\u77ed\u8ddd\u79bb\u5373\u88ab\u8ba1\u7b97\u51fa\u6765\u3002\u6bd4\u5982\u9009C\u3002\u5bf9C\u8fdb\u884c\u6807\u8bb0\u3002 \u00a0 A B [&hellip;]<\/p>\n<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pa4z28-8o","_links":{"self":[{"href":"https:\/\/www.yesybl.com\/index.php?rest_route=\/wp\/v2\/posts\/520"}],"collection":[{"href":"https:\/\/www.yesybl.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yesybl.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yesybl.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yesybl.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=520"}],"version-history":[{"count":5,"href":"https:\/\/www.yesybl.com\/index.php?rest_route=\/wp\/v2\/posts\/520\/revisions"}],"predecessor-version":[{"id":619,"href":"https:\/\/www.yesybl.com\/index.php?rest_route=\/wp\/v2\/posts\/520\/revisions\/619"}],"wp:attachment":[{"href":"https:\/\/www.yesybl.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yesybl.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yesybl.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}