{"id":521,"date":"2017-04-28T14:28:32","date_gmt":"2017-04-28T06:28:32","guid":{"rendered":"http:\/\/kylelv.com\/?p=521"},"modified":"2018-01-18T17:15:58","modified_gmt":"2018-01-18T09:15:58","slug":"bzoj-1626-usaco2007-decbuilding-roads-%e4%bf%ae%e5%bb%ba%e9%81%93%e8%b7%af-%e6%9c%80%e5%b0%8f%e7%94%9f%e6%88%90%e6%a0%91","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=521","title":{"rendered":"bzoj 1626: [Usaco2007 Dec]Building Roads \u4fee\u5efa\u9053\u8def  &#8212; \u6700\u5c0f\u751f\u6210\u6811"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fdefb1bd9ef\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fdefb1bd9ef\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#1626_Usaco2007_DecBuilding_Roads_%E4%BF%AE%E5%BB%BA%E9%81%93%E8%B7%AF\" title=\"1626: [Usaco2007 Dec]Building Roads \u4fee\u5efa\u9053\u8def\">1626: [Usaco2007 Dec]Building Roads \u4fee\u5efa\u9053\u8def<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=521\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1626_Usaco2007_DecBuilding_Roads_%E4%BF%AE%E5%BB%BA%E9%81%93%E8%B7%AF\"><\/span>1626: [Usaco2007 Dec]Building Roads \u4fee\u5efa\u9053\u8def<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a05 Sec\u00a0\u00a0Memory Limit:\u00a064 MB<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>Farmer John\u6700\u8fd1\u5f97\u5230\u4e86\u4e00\u4e9b\u65b0\u7684\u519c\u573a\uff0c\u4ed6\u60f3\u65b0\u4fee\u4e00\u4e9b\u9053\u8def\u4f7f\u5f97\u4ed6\u7684\u6240\u6709\u519c\u573a\u53ef\u4ee5\u7ecf\u8fc7\u539f\u6709\u7684\u6216\u662f\u65b0\u4fee\u7684\u9053\u8def\u4e92\u8fbe\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ece\u4efb\u4e00\u4e2a\u519c\u573a\u90fd\u53ef\u4ee5\u7ecf\u8fc7\u4e00\u4e9b\u9996\u5c3e\u76f8\u8fde\u9053\u8def\u5230\u8fbe\u5269\u4e0b\u7684\u6240\u6709\u519c\u573a\uff09\u3002\u6709\u4e9b\u519c\u573a\u4e4b\u95f4\u539f\u672c\u5c31\u6709\u9053\u8def\u76f8\u8fde\u3002 \u6240\u6709N(1 &lt;= N &lt;= 1,000)\u4e2a\u519c\u573a\uff08\u75281..N\u987a\u6b21\u7f16\u53f7\uff09\u5728\u5730\u56fe\u4e0a\u90fd\u8868\u793a\u4e3a\u5750\u6807\u4e3a(X_i, Y_i)\u7684\u70b9(0 &lt;= X_i &lt;= 1,000,000\uff1b0 &lt;= Y_i &lt;= 1,000,000)\uff0c\u4e24\u4e2a\u519c\u573a\u95f4\u9053\u8def\u7684\u957f\u5ea6\u81ea\u7136\u5c31\u662f\u4ee3\u8868\u5b83\u4eec\u7684\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u3002\u73b0\u5728Farmer John\u4e5f\u544a\u8bc9\u4e86\u4f60\u519c\u573a\u95f4\u539f\u6709\u7684M(1 &lt;= M &lt;= 1,000)\u6761\u8def\u5206\u522b\u8fde\u63a5\u4e86\u54ea\u4e24\u4e2a\u519c\u573a\uff0c\u4ed6\u5e0c\u671b\u4f60\u8ba1\u7b97\u4e00\u4e0b\uff0c\u4e3a\u4e86\u4f7f\u5f97\u6240\u6709\u519c\u573a\u8fde\u901a\uff0c\u4ed6\u6240\u9700\u5efa\u9020\u9053\u8def\u7684\u6700\u5c0f\u603b\u957f\u662f\u591a\u5c11\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>* \u7b2c1\u884c: 2\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570\uff1aN \u548c M<\/p>\n<p>* \u7b2c2..N+1\u884c: \u7b2ci+1\u884c\u4e3a2\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570\uff1aX_i\u3001Y_i * \u7b2cN+2..N+M+2\u884c: \u6bcf\u884c\u75282\u4e2a\u4ee5\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570i\u3001j\u63cf\u8ff0\u4e86\u4e00\u6761\u5df2\u6709\u7684\u9053\u8def\uff0c \u8fd9\u6761\u9053\u8def\u8fde\u63a5\u4e86\u519c\u573ai\u548c\u519c\u573aj<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>* \u7b2c1\u884c: \u8f93\u51fa\u4f7f\u6240\u6709\u519c\u573a\u8fde\u901a\u6240\u9700\u5efa\u8bbe\u9053\u8def\u7684\u6700\u5c0f\u603b\u957f\uff0c\u4fdd\u75592\u4f4d\u5c0f\u6570\uff0c\u4e0d\u5fc5\u505a \u4efb\u4f55\u989d\u5916\u7684\u53d6\u6574\u64cd\u4f5c\u3002\u4e3a\u4e86\u907f\u514d\u7cbe\u5ea6\u8bef\u5dee\uff0c\u8ba1\u7b97\u519c\u573a\u95f4\u8ddd\u79bb\u53ca\u7b54\u6848\u65f6 \u8bf7\u4f7f\u752864\u4f4d\u5b9e\u578b\u53d8\u91cf<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\"><span class=\"sampledata\">4 1<br \/>\n1 1<br \/>\n3 1<br \/>\n2 3<br \/>\n4 3<br \/>\n1 4<\/span><\/span>\u8f93\u5165\u8bf4\u660e:<\/p>\n<p>FJ\u4e00\u5171\u67094\u4e2a\u5750\u6807\u5206\u522b\u4e3a(1,1)\uff0c(3,1)\uff0c(2,3)\uff0c(4,3)\u7684\u519c\u573a\u3002\u519c\u573a1\u548c\u519c\u573a<br \/>\n4\u4e4b\u95f4\u539f\u672c\u5c31\u6709\u9053\u8def\u76f8\u8fde\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p><span class=\"sampledata\">4.00<\/span><\/p>\n<p>\u8f93\u51fa\u8bf4\u660e:<\/p>\n<p>FJ\u9009\u62e9\u5728\u519c\u573a1\u548c\u519c\u573a2\u95f4\u5efa\u4e00\u6761\u957f\u5ea6\u4e3a2.00\u7684\u9053\u8def\uff0c\u5728\u519c\u573a3\u548c\u519c\u573a4\u95f4\u5efa\u4e00<br \/>\n\u6761\u957f\u5ea6\u4e3a2.00\u7684\u9053\u8def\u3002\u8fd9\u6837\uff0c\u6240\u5efa\u9053\u8def\u7684\u603b\u957f\u4e3a4.00\uff0c\u5e76\u4e14\u8fd9\u662f\u6240\u6709\u65b9\u6848\u4e2d\u9053\u8def<br \/>\n\u603b\u957f\u6700\u5c0f\u7684\u4e00\u79cd\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\r\n#include&lt;cmath&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define ll long long\r\n#define N 1010\r\n#define db double\r\ninline int rd()\r\n{\r\n    int x=0,f=1;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x*f;\r\n}\r\nstruct qaz{int a,b;db v;}e[N*N],q[N];\r\nbool cmp(qaz a,qaz b){return a.v&lt;b.v;}\r\ndb dis(int a,int b)\r\n{\r\n    ll x=q[a].a-q[b].a,y=q[a].b-q[b].b;\r\n    return sqrt(x*x+y*y);\r\n}\r\nint cnt,fa[N];\r\nvoid add(int a,int b){e[++cnt]=(qaz){a,b,dis(a,b)};}\r\nint findf(int x){return x==fa[x]?x:fa[x]=findf(fa[x]);}\r\nint n,m,x,y;\r\ndb ans;\r\nint main()\r\n{\r\n    n=rd();m=rd();\r\n    int i,j,f1,f2;\r\n    for(i=1;i&lt;=n;i++)\r\n    {\r\n        q[i].a=rd();q[i].b=rd();\r\n        fa[i]=i;\r\n    }\r\n    for(i=1;i&lt;=m;i++)\r\n    {\r\n        x=rd();y=rd();\r\n        x=findf(x);y=findf(y);\r\n        fa[y]=x;\r\n    }\r\n    for(int i=1;i&lt;=n;i++) fa[i]=findf(i);\r\n    for(i=1;i&lt;=n;i++)\r\n    {\r\n        for(j=1;j&lt;=n;j++)\r\n        {\r\n            if(i==j) continue;\r\n            if(fa[i]!=fa[j]) add(i,j);\r\n        }\r\n    }\r\n    sort(e+1,e+cnt+1,cmp);\r\n    for(int i=1;i&lt;=cnt;i++)\r\n    {\r\n        x=findf(e[i].a);y=findf(e[i].b);\r\n        if(x!=y)\r\n        {\r\n            ans+=e[i].v;\r\n            fa[y]=x;\r\n        }\r\n    }\r\n    printf(\"%.2lf\\n\",ans);\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1626: [Usaco2007 Dec]Building Roads \u4fee\u5efa\u9053\u8def Time Li [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[56],"class_list":["post-521","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-56"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=521"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/521\/revisions"}],"predecessor-version":[{"id":523,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/521\/revisions\/523"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}