{"id":79,"date":"2026-01-10T09:09:49","date_gmt":"2026-01-10T01:09:49","guid":{"rendered":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/?p=79"},"modified":"2026-01-16T19:29:41","modified_gmt":"2026-01-16T11:29:41","slug":"dijkstra%e7%ae%97%e6%b3%95%e6%b1%82%e6%9c%80%e7%9f%ad%e8%b7%af","status":"publish","type":"post","link":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/2026\/01\/10\/dijkstra%e7%ae%97%e6%b3%95%e6%b1%82%e6%9c%80%e7%9f%ad%e8%b7%af\/","title":{"rendered":"Dijkstra\u7b97\u6cd5\u6c42\u6700\u77ed\u8def"},"content":{"rendered":"\n<p>P3371: \u5355\u6e90\u6700\u77ed\u8def(\u5f31\u5316\u7248)<a href=\"https:\/\/www.luogu.com.cn\/problem\/P3371\" data-type=\"link\" data-id=\"https:\/\/www.luogu.com.cn\/problem\/P3371\">https:\/\/www.luogu.com.cn\/problem\/P3371<\/a><\/p>\n\n\n\n<p>P4779 \u5355\u6e90\u6700\u77ed\u8def(\u6807\u51c6\u7248): <a href=\"https:\/\/www.luogu.com.cn\/problem\/P4779\" data-type=\"link\" data-id=\"https:\/\/www.luogu.com.cn\/problem\/P4779\">https:\/\/www.luogu.com.cn\/problem\/P4779<\/a><\/p>\n\n\n\n<p>\u89c6\u9891\u8be6\u89e3: <a href=\"https:\/\/www.bilibili.com\/video\/BV1QESyYGE55\/?spm_id_from=333.337.search-card.all.click\">https:\/\/www.bilibili.com\/video\/BV1QESyYGE55\/?spm_id_from=333.337.search-card.all.click<\/a><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u9898\u76ee\u4e2d\u6709<strong>\u91cd\u8fb9<\/strong>\uff0c\u4f7f\u7528\u90bb\u63a5\u77e9\u9635\u9700\u52a0\u5165\u91cd\u8fb9\u5224\u65ad\uff0c\u6240\u4ee5\u4f7f\u7528\u90bb\u63a5\u8868\u4f1a\u66f4\u65b9\u4fbf<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>struct edge {\n\tll v, w;\n\tbool friend operator &lt;(edge a,edge b){\n\t\treturn a.w &gt; b.w;\n\t} \/\/ \u91cd\u8f7d\n};\npriority_queue&lt;edge&gt; q; \/\/ \u9ed8\u8ba4\u4e3a\u5927\u6839\u5806\uff0c\u4f7f\u7528edge\u540e\u53d8\u4e3a\u5c0f\u6839\u5806<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4e3b\u51fd\u6570\nvoid dij(){\n        \/\/ \u5806\u4f18\u5316\n\twhile (!q.empty()) {\n\t\tedge tmp = q.top();\n\t\tq.pop();\n\t\tll u = tmp.v;\n\t\tif(visited&#91;u]) continue; \/\/ \u5df2\u7ecf\u662f\u6700\u5c0f\u503c\u4e86\uff0c\u9000\u51fa\n\t\tvisited&#91;u] = 1;\n\t\tfor (auto ed : a&#91;u]) { \/\/ \u904d\u5386\u5b83\u6307\u5411\u7684\u6240\u6709\u70b9\n\t\t\tint v = ed.v;\n\t\t\tif (!visited&#91;v]) { \/\/ \u6ce8\u610f\u9700\u8981\u5224\u65ad\u80fd\u5426\u8bbf\u95ee!\n\t\t\t\tdis&#91;v] = min(dis&#91;v],tmp.w + ed.w);\n\t\t\t\tq.push({v, dis&#91;v]});\n\t\t\t}\n\t\t}\n\t} \n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>int main() {\n\tios::sync_with_stdio(0);\n\tcin.tie(0);\n\t\n\tmemset(dis, 0x7f7f7f7f7f7f7f7f, sizeof(dis));\n\n\tcin &gt;&gt; n &gt;&gt; m &gt;&gt; s;\n\tdis&#91;s]=0;\/\/ \u7b2c\u4e00\u4e2a\u70b9\u5230\u81ea\u5df1\u7684\u8ddd\u79bb\u4e3a0\n\tfor (int d1=1;d1&lt;=m;d1++) {\n\t\tint u, v ,w;\n\t\tcin &gt;&gt; u &gt;&gt; v &gt;&gt; w;\n\t\ta&#91;u].push_back({v, w});\n\t}\n\tq.push({s, 0});\n\tdij();\n\tfor (int d1=1;d1&lt;=n;d1++) {\n\t  if (dis&#91;d1] &gt; 1e15) cout &lt;&lt; INT_MAX &lt;&lt; \" \" ; \/\/INT_MAX\u5728climits\u5e93\u4e2d\n\t  else cout &lt;&lt; dis&#91;d1] &lt;&lt; \" \";\n\t}\n\treturn 0;\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>P3371: \u5355\u6e90\u6700\u77ed\u8def(\u5f31\u5316&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":5,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions\/97"}],"wp:attachment":[{"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/\u9f50\u6cb3\u4e00\u4e2d.cn\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}