{"id":254,"date":"2023-07-18T14:36:04","date_gmt":"2023-07-18T06:36:04","guid":{"rendered":"https:\/\/solost.cn\/?p=254"},"modified":"2023-07-18T14:36:04","modified_gmt":"2023-07-18T06:36:04","slug":"383","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=254","title":{"rendered":"\u201c\u8303\u5f0f\u676f\u201d2023\u725b\u5ba2\u6691\u671f\u591a\u6821\u8bad\u7ec3\u84251 &#8211; K &#8211; Subdivision"},"content":{"rendered":"<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/57355\/K\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff0cn\u4e2a\u70b9\uff0cm\u6761\u8fb9\uff0c\u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u4e00\u6761\u8fb9\u4e2d\u95f4\u589e\u52a0\u4e00\u4e2a\u70b9\uff0c\u8fb9\u7684\u957f\u5ea6\u8fd8\u662f1\uff0c\u95ee\u4f60\u4ece1\u5230\u5404\u70b9\u8ddd\u79bb\u5c0f\u4e8e\u7b49\u4e8ek\u7684\u70b9\u7684\u4e2a\u6570\u6700\u591a\u662f\u591a\u5c11\u3002<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u6bd4\u8d5b\u8fc7\u7a0b\u4e2d\u53ea\u60f3\u5230\u4e86\u8fd9\u9053\u9898\u7684\u4e00\u90e8\u5206\uff0c\u60f3\u7740\u5c06\u52a0\u70b9\u8f6c\u6362\u6210\u65ad\u73af\u548c\u5728\u53f6\u5b50\u8282\u70b9\u589e\u52a0\u513f\u5b50\uff0c\u4f46\u662f\u5728\u5bf9\u6df1\u5ea6\u6ca1\u6709\u5370\u8c61\u7684\u8fb9\u90a3\u53ef\u4ee5\u4efb\u610f\u52a0\u70b9\uff0c\u4e0d\u4f1a\u589e\u52a0\u6df1\u5ea6<\/p>\n<p>\u6240\u4ee5\u6b63\u89e3\u662f\uff0c\u5bfb\u627e\u4e0d\u4f1a\u5f71\u54cd\u6df1\u5ea6\u7684\u8fb9\uff0c\u52a0\u6ee1\u3002<\/p>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code class=\"lang-cpp\">#include &lt;map&gt;\n#include &lt;set&gt;\n#include &lt;cmath&gt;\n#include &lt;queue&gt;\n#include &lt;stack&gt;\n#include &lt;vector&gt;\n#include &lt;bitset&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n\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);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\n\nvector&lt;int&gt; a[N];\n\nvoid solve()\n{\n    int n, m, k;\n    cin &gt;&gt; n &gt;&gt; m &gt;&gt; k;\n    for(int i = 1; i &lt;= m; i++){\n        int x, y;\n        cin &gt;&gt; x &gt;&gt; y;\n        a[x].push_back(y);\n        a[y].push_back(x);\n    }\n    vector&lt;int&gt; dist(n + 10, -1), par(n + 10), inner(n + 10);\/\/dist\u6df1\u5ea6\uff0cpar\u5b58\u653e\u8fb9\uff0c\u7528\u4e8e\u627e\u51fa\u5bf9\u6df1\u5ea6\u6ca1\u6709\u5f71\u54cd\u7684\u8fb9\uff0cinner\u7528\u4e8e\u8bb0\u5f55\u54ea\u4e2a\u662f\u6811\u8fb9\n    queue&lt;int&gt; q;\n    q.push(1);\n    dist[1] = 0;\n    while(q.size()){\n        auto t = q.front();\n        q.pop();\n        for(auto x : a[t]){\n            if(dist[x] != -1) continue;\n            q.push(x);\n            dist[x] = dist[t] + 1;\/\/\u8ba1\u7b97\u6df1\u5ea6\n            par[x] = t;\n            inner[t] = 1;\/\/\u6709\u513f\u5b50\u7684\u8282\u70b9\u4e00\u5b9a\u662f\u6811\u8fb9\n        }\n    }\n    ll ans = 1;\n    for(int i = 2; i &lt;= n; i++){\n        if(dist[i] == -1 || dist[i] &gt; k) continue;\n        ll cnt = 0;\n        for(auto x : a[i]){\n            if(par[x] == i || par[i] == x)\/\/\u5982\u679c\u8fd9\u6761\u8fb9\u88ab\u6807\u8bb0\u8fc7\uff0c\u8bc1\u660e\u662f\u5fc5\u987b\u6709\u7684\n                continue;\n            ++cnt;\/\/\u5426\u5219\u5c31\u662f\u5bf9\u6df1\u5ea6\u6ca1\u6709\u5f71\u54cd\u7684\u8fb9\n        }\n        if(!inner[i])\n            cnt = max(cnt, 1ll);\/\/\u5982\u679c\u4e0d\u662f\u6811\u8fb9\uff0c\u90a3\u5c31\u81f3\u5c11\u53ef\u4ee5\u628a\u81ea\u8eab\u52a0\u6ee1\n        ans += (k - dist[i]) * cnt + 1;\/\/+1\u662f\u6307\u80fd\u5230\u8fbe1\u7684\u90fd\u7b97\u4e00\u4e2a\n    }\n    cout &lt;&lt; ans &lt;&lt; endl;\n}\nint main()\n{\n    \/\/ IOS;\n    int _ = 1;\n    \/\/ cin &gt;&gt; _;\n    while (_--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u7ed9\u4f60\u4e00\u4e2a\u65e0\u5411\u56fe\uff0cn\u4e2a\u70b9\uff0cm\u6761\u8fb9\uff0c\u4f60\u53ef\u4ee5\u5728\u4efb\u610f\u4e00\u6761\u8fb9\u4e2d\u95f4\u589e\u52a0\u4e00\u4e2a\u70b9\uff0c\u8fb9\u7684\u957f\u5ea6\u8fd8\u662f1\uff0c\u95ee\u4f60\u4ece1\u5230\u5404\u70b9\u8ddd\u79bb\u5c0f\u4e8e\u7b49\u4e8ek\u7684\u70b9\u7684\u4e2a\u6570\u6700\u591a\u662f\u591a\u5c11\u3002 \u9898\u89e3 \u6bd4\u8d5b\u8fc7\u7a0b\u4e2d\u53ea\u60f3\u5230\u4e86\u8fd9\u9053\u9898\u7684\u4e00\u90e8\u5206\uff0c\u60f3\u7740\u5c06\u52a0\u70b9\u8f6c\u6362\u6210\u65ad\u73af\u548c\u5728\u53f6\u5b50\u8282\u70b9\u589e\u52a0\u513f\u5b50\uff0c\u4f46\u662f\u5728\u5bf9\u6df1\u5ea6\u6ca1\u6709\u5370\u8c61\u7684\u8fb9\u90a3\u53ef\u4ee5\u4efb\u610f\u52a0\u70b9\uff0c\u4e0d\u4f1a\u589e\u52a0\u6df1\u5ea6 \u6240\u4ee5\u6b63\u89e3\u662f\uff0c\u5bfb\u627e\u4e0d\u4f1a\u5f71\u54cd\u6df1\u5ea6\u7684\u8fb9\uff0c\u52a0\u6ee1\u3002 \u4ee3\u7801 #include &lt;map&gt; #include &lt;set&gt; #include &lt;cmath&gt; #include &lt;queue&gt; #include &lt;stack&gt; #include &lt;vector&gt; #include &lt;bitset&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;unordered_map&gt; #include &lt;unordered_set&gt; #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); [&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":[25,5],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-solution","tag-bfs","tag-5"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/254","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=254"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/254\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}