{"id":72,"date":"2023-03-14T22:06:24","date_gmt":"2023-03-14T14:06:24","guid":{"rendered":"https:\/\/solost.cn\/?p=72"},"modified":"2023-03-14T22:06:24","modified_gmt":"2023-03-14T14:06:24","slug":"162","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=72","title":{"rendered":"2023\u5e74\u4e2d\u56fd\u9ad8\u6821\u8ba1\u7b97\u673a\u5927\u8d5b-\u56e2\u961f\u7a0b\u5e8f\u8bbe\u8ba1\u5929\u68af\u8d5b\uff08GPLT\uff09\u4e0a\u6d77\u7406\u5de5\u5927\u5b66\u6821\u5185\u9009\u62d4\u8d5b\uff08\u540c\u6b65\u8d5b) -F-\u5750\u706b\u8f66"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image-7.png\" alt=\"image.png\" title=\"image.png\"><\/p>\n<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/52244\/F\">\u94fe\u63a5<\/a><\/p>\n<h2>solution<\/h2>\n<p>\u8fd9\u9053\u9898\u4e5f\u6ca1\u5565\u96be\u70b9\uff0c\u7eaf\u5c5e\u8111\u6b8b\u3002\u5c31\u662fBFS\u641c\u7d22\u5c31\u884c\u4e86\u3002\u6ce8\u610f\u641c\u7d22\u7684\u65f6\u5019\u7ef4\u62a4\u4e00\u4e0b\u72b6\u6001\u5c31\u884c\u3002<\/p>\n<pre><code class=\"lang-cpp\">#include&lt;map&gt;\n#include&lt;set&gt;\n#include&lt;stack&gt;\n#include&lt;queue&gt;\n#include&lt;cmath&gt;\n#include&lt;vector&gt;\n#include&lt;bitset&gt;\n#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;fstream&gt;\n#include&lt;cstdlib&gt;\n#include&lt;iostream&gt;\n#include&lt;algorithm&gt;\n#include&lt;unordered_map&gt;\n\nusing namespace std;\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int,int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\nvector&lt;PII&gt; g[N];\nint dist[N], cnt[N];\nvoid spfa(){\n    queue&lt;PII&gt; q;\n    memset(dist, 0x3f, sizeof dist);\n    memset(cnt, 0x3f, sizeof cnt);\n    dist[1] = 0;\n    cnt[1] = 1;\n    q.push({1, 0});\n    while(q.size()){\n        auto t = q.front();\n        q.pop();\n        for(auto [x, y] : g[t.x]){\n            if(cnt[x] &gt;= cnt[t.x] + 1){\n                cnt[x] = cnt[t.x] + 1;\n                if(dist[x] &gt; dist[t.x] + y){\n                    dist[x] = dist[t.x] + y;\n                    q.push({x, dist[x]});\n                }\n            }\n        }\n    }\n}\n\nvoid solve(){\n    int n, m;\n    cin &gt;&gt; n &gt;&gt; m;\n    for(int i = 1; i &lt;= m; i++){\n        int a, b, c;\n        cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;\n        g[a].push_back({b, c});\n        g[b].push_back({a, c});\n    }\n    spfa();\n    cout &lt;&lt; cnt[n] &lt;&lt; &quot; &quot; &lt;&lt; dist[n] &lt;&lt; endl;\n}\nint main(){\n    \/\/ IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while(t--){\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 solution \u8fd9\u9053\u9898\u4e5f\u6ca1\u5565\u96be\u70b9\uff0c\u7eaf\u5c5e\u8111\u6b8b\u3002\u5c31\u662fBFS\u641c\u7d22\u5c31\u884c\u4e86\u3002\u6ce8\u610f\u641c\u7d22\u7684\u65f6\u5019\u7ef4\u62a4\u4e00\u4e0b\u72b6\u6001\u5c31\u884c\u3002 #include&lt;map&gt; #include&lt;set&gt; #include&lt;stack&gt; #include&lt;queue&gt; #include&lt;cmath&gt; #include&lt;vector&gt; #include&lt;bitset&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;fstream&gt; #include&lt;cstdlib&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;unordered_map&gt; using namespace std; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); typedef long long ll; typedef pair&lt;int,int&gt; PII; typedef unsigned long long ull; const int INF = 0x3f3f3f3f, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[32,31,27],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-solution","tag-spfa","tag-31","tag-27"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/72\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}