{"id":25,"date":"2026-05-08T23:08:42","date_gmt":"2026-05-08T15:08:42","guid":{"rendered":"https:\/\/done.baka233.top\/?p=25"},"modified":"2026-05-15T22:03:42","modified_gmt":"2026-05-15T14:03:42","slug":"5-8-%e6%97%a5%e5%bf%97","status":"publish","type":"post","link":"https:\/\/done.baka233.top\/index.php\/2026\/05\/08\/5-8-%e6%97%a5%e5%bf%97\/","title":{"rendered":"5.8 \u65e5\u5fd7"},"content":{"rendered":"<h3>\u524d\u8a00<\/h3>\n<p>\u8fd9\u662f\u8bfe\u4e0a\u8bb2\u8fc7\u7684\u9898\u76ee\uff0c\u7531\u4e8e\u8bb2\u5f97\u86ee\u5feb\u7684\uff08\u5176\u5b9e\u662f\u849f\u84bb\u5438\u6536\u5f97\u6162\uff09\uff0c\u6240\u4ee5\u6211\u4e0d\u5f97\u4e0d\u518d\u6765\u634b\u4e00\u634b\u601d\u8def\u3002<\/p>\n<h3>\u6b63\u6587<\/h3>\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/www.luogu.com.cn\/problem\/P10289\">luoguP10289<\/a>\u3002<\/p>\n<p>\u9898\u9762\u7b80\u5355\u63cf\u8ff0\u5373\u662f\uff1a\u6709\u4e00\u4e2a\u7531$n$\u4e2a\u70b9\u4e0e$n-1$\u6761\u8fb9\u6743\u4e3a1\u7684\u65e0\u5411\u8fb9\u6784\u6210\u7684\u8fde\u901a\u56fe\uff08\u5373\u662f\u4e00\u68f5\u6811\uff09\uff0c\u70b9\u4ece1\u5230$n$\u8fdb\u884c\u7f16\u53f7\u3002\u540c\u65f6\uff0c\u5728\u8fd9\u68f5\u6811\u4e0a\u7684\u7ed3\u70b9\u4e2d\u6709$k$\u4e2a\u7279\u6b8a\u70b9\u4e24\u4e24\u4e4b\u95f4\u8fde\u6709\u4e00\u6761\u201c\u65e0\u5f62\u7684\u201d\u8fb9\u6743\u4e3a0\u7684\u65e0\u5411\u8fb9\u3002\u7ed9\u51fa$q$\u7ec4\u8be2\u95ee\uff0c\u6bcf\u7ec4\u8be2\u95ee\u56de\u7b54$u$\u70b9\u5230$v$\u70b9\u7684\u6700\u77ed\u8ddd\u79bb\u3002<\/p>\n<p>\u9996\u5148\u8fd9\u662f\u4e00\u68f5\u8fb9\u6743\u4e3a1\u7684\u6811\uff0c\u6811\u4e0a$u,\\, v$\u4e24\u70b9\u8ddd\u79bb\u5e94\u4e3a$$dis(u,\\, v)=depth(u)+depth(v)-2*depth(lca(u,\\, v)).$$\u4f46\u7279\u6b8a\u4e4b\u5904\u5c31\u5728\u4e8e\u201c\u65e0\u5f62\u7684\u201d\u8fb9\uff0c\u8fd9\u6837\uff0c\u6811\u4e0a$u,\\, v$\u4e24\u70b9\u95f4\u7684\u8def\u5f84\u5c31\u4e0d\u6b62\u4e00\u6761\u3002\u4ece\u6700\u77ed\u8ddd\u79bb\u8003\u8651\uff0c\u53d1\u73b0\u4e8b\u5b9e\u4e0a\u53ea\u4f1a\u591a\u51fa\u4e00\u6761\u8def\u5f84\uff0c\u5373\u5148\u4ece$u$\u70b9\u5230\u8ddd\u79bb$u$\u70b9\u6700\u8fd1\u7684\u7279\u6b8a\u70b9$a$\uff0c\u518d\u4ece$a$\u70b9\u82b1\u8d390\u5230\u8ddd\u79bb$v$\u70b9\u6700\u8fd1\u7684\u7279\u6b8a\u70b9$b$\uff0c\u6700\u540e\u4ece$b$\u5230$v$\u3002<\/p>\n<p>\u90a3\u4e48\u73b0\u5728\uff0c\u8003\u8651\u6c42$f_{i}$\u8868\u793a$i$\u70b9\u5230\u8ddd\u79bb$i$\u70b9\u6700\u8fd1\u7279\u6b8a\u70b9\u7684\u8ddd\u79bb\uff0c\u5e0c\u671b\u8dd1\u4e00\u904d\u6811\u4fbf\u80fd\u6c42\u51fa\u6765\u3002\u53ef\u4ee5\u4f7f\u6bcf\u4e00\u4e2a\u7279\u6b8a\u70b9<strong>\u540c\u65f6<\/strong>\u5411\u56db\u5468\u6269\u6563\uff0c\u82e5\u67d0\u4e2a\u7279\u6b8a\u70b9$s$<strong>\u7387\u5148\u6269\u6563\u5230<\/strong>\u67d0\u4e2a\u672a\u88ab\u6807\u8bb0\u7684\u70b9$t$\uff0c\u5219\u8bf4\u660e$t$\u70b9\u7684\u6700\u8fd1\u7279\u6b8a\u70b9\u4e3a$s$\uff0c\u5176\u95f4\u8ddd\u79bb\u5728\u6269\u6563\u7684\u540c\u65f6\u8bb0\u5f55\u5373\u53ef\uff1b\u82e5\u6269\u6563\u5230\u5df2\u88ab\u6807\u8bb0\u7684\u70b9\uff0c\u5219\u505c\u6b62\u8be5\u65b9\u5411\u4e0a\u7684\u6269\u6563\uff0c\u56e0\u4e3a\u5df2\u7ecf\u6709\u522b\u7684\u7279\u6b8a\u70b9\u7387\u5148\u6269\u6563\u5230\u8be5\u70b9\u5e76\u6807\u8bb0\u4e86\u5b83\u3002\u90a3\u4e48\uff0c\u6bcf\u4e2a\u70b9\u53ea\u4f1a\u88ab\u8bbf\u95ee\u5e76\u6807\u8bb0\u4e00\u6b21\uff0c\u5373\u53ea\u8dd1\u4e86\u4e00\u904d\u6811\u3002<\/p>\n<p>\u6700\u540e\u7b54\u6848\u5c31\u662f$\\min \\{dis(u,\\, v),\\, f_{u}+f_{v}\\}$\u3002\u65e0\u6838\u5fc3\u4ee3\u7801\uff0c\u6c42\u4e86\u4e00\u4e2alca\uff0c\u518d\u52a0\u4e0a\u7528\u4e8e\u5b9e\u73b0\u201c\u6269\u6563\u201d\u7684bfs\u6c42\u51fa$f_{i}$\u3002\u6574\u4e2abfs\uff1a<\/p>\n<pre><code class=\"\" data-line=\"\">void bfs(){\n\tqueue &lt;pair &lt;int, int&gt; &gt; que;\n\tmemset(f, 0x3f, sizeof f);\n\tfor(int i, u; i &lt;= k; i++){\n\t\tcin &gt;&gt; u, f[u] = 0;\n\t\tque.push({u, 0}); \/\/ \u7279\u6b8a\u70b9\u5148\u5165\u961f\n\t}\n\twhile(!que.empty()){\n\t\tauto t = que.front();\n\t\tque.pop();\n\t\tfor(int v : tree[t.first]){\n\t\t\tif(f[v] != 0x3f3f3f3f) continue; \/\/ \u975e\u6781\u5927\u503c\uff0c\u5df2\u88ab\u6807\u8bb0\n\t\t\tf[v] = t.second + 1;\n\t\t\tque.push({v, f[v]});\n\t\t}\n\t}\n}<\/code><\/pre>\n<h3>\u540e\u8bdd<\/h3>\n<p>\u4e00\u7bc7\u6587\u7ae0\u53ea\u634b\u4e00\u9053\u7b80\u5355\u9898\u592a\u6d6a\u8d39\u4e86\uff0c\u53ef\u60dc\u6211\u65f6\u95f4\u592a\u4e0d\u5145\u88d5\uff0c\u4ee5\u540e\u53ea\u80fd\u7cbe\u7b80\u601d\u8def\u63cf\u8ff0\u4e86\u2026\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u8fd9\u662f\u8bfe\u4e0a\u8bb2\u8fc7\u7684\u9898\u76ee\uff0c\u7531\u4e8e\u8bb2\u5f97\u86ee\u5feb\u7684\uff08\u5176\u5b9e\u662f\u849f\u84bb\u5438\u6536\u5f97\u6162\uff09\uff0c\u6240\u4ee5\u6211\u4e0d\u5f97\u4e0d\u518d\u6765\u634b\u4e00\u634b\u601d\u8def\u3002 \u6b63\u6587 \u9898\u76ee\u94fe\u63a5\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/done.baka233.top\/index.php\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}