{"id":229,"date":"2010-04-19T14:35:00","date_gmt":"2010-04-19T06:35:00","guid":{"rendered":"http:\/\/localhost\/?p=229"},"modified":"2010-04-19T14:35:00","modified_gmt":"2010-04-19T06:35:00","slug":"usaco2008nov_comfort_cows_cheer","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=229","title":{"rendered":"[Usaco2008Nov]\u5b89\u6170\u5976\u725bcheer"},"content":{"rendered":"\n<p>[Usaco2008Nov]\u5b89\u6170\u5976\u725bcheer<\/p>\n<p>Time Limit:10000MS  Memory Limit:165536K<br \/>Total Submit:18 Accepted:15 <br \/>Case Time Limit:1000MS<\/p>\n<p><strong>Description <\/strong><\/p>\n<p>Farmer John\u53d8\u5f97\u975e\u5e38\u61d2, \u4ed6\u4e0d\u60f3\u518d\u7ee7\u7eed\u7ef4\u62a4\u4f9b\u5976\u725b\u4e4b\u95f4\u4f9b\u901a\u884c\u7684\u9053\u8def. \u9053\u8def\u88ab\u7528\u6765\u8fde\u63a5N <br \/>(5 &lt;= N &lt;= 10,000)\u4e2a\u7267\u573a, \u7267\u573a\u88ab\u8fde\u7eed\u5730\u7f16\u53f7\u4e3a1..N. \u6bcf\u4e00\u4e2a\u7267\u573a\u90fd\u662f\u4e00\u4e2a\u5976\u725b\u7684\u5bb6. <br \/>FJ\u8ba1\u5212\u9664\u53bbP(N-1 &lt;= P &lt;= 100,000)\u6761\u9053\u8def\u4e2d\u5c3d\u53ef\u80fd\u591a\u7684\u9053\u8def, \u4f46\u662f\u8fd8\u8981\u4fdd\u6301\u7267\u573a\u4e4b\u95f4 <br \/>\u7684\u8fde\u901a\u6027. \u4f60\u9996\u5148\u8981\u51b3\u5b9a\u90a3\u4e9b\u9053\u8def\u662f\u9700\u8981\u4fdd\u7559\u7684N-1\u6761\u9053\u8def. <\/p>\n<p>\u7b2cj\u6761\u53cc\u5411\u9053\u8def\u8fde\u63a5\u4e86\u7267\u573aS_j\u548cE_j (1 &lt;= S_j &lt;= N; 1 &lt;= E_j &lt;= N; S_j != E_j), <br \/>\u800c\u4e14\u8d70\u5b8c\u5b83\u9700\u8981L_j (0 &lt;= L_j &lt;= 1,000)\u7684\u65f6\u95f4. \u6ca1\u6709\u4e24\u4e2a\u7267\u573a\u662f\u88ab\u4e00\u6761\u4ee5\u4e0a\u7684\u9053\u8def\u6240\u8fde\u63a5. <\/p>\n<p>\u5976\u725b\u4eec\u975e\u5e38\u4f24\u5fc3, \u56e0\u4e3a\u5979\u4eec\u7684\u4ea4\u901a\u7cfb\u7edf\u88ab\u524a\u51cf\u4e86. \u4f60\u9700\u8981\u5230\u6bcf\u4e00\u4e2a\u5976\u725b\u7684\u4f4f\u5904\u53bb\u5b89\u6170\u5979\u4eec. \u6bcf\u6b21 <br \/>\u4f60\u5230\u8fbe\u7b2ci\u4e2a\u7267\u573a\u7684\u65f6\u5019(\u5373\u4f7f\u4f60\u5df2\u7ecf\u5230\u8fc7), \u4f60\u5fc5\u987b\u82b1\u53bbC_i (1 &lt;= C_i &lt;= 1,000)\u7684 <br \/>\u65f6\u95f4\u548c\u5976\u725b\u4ea4\u8c08. <\/p>\n<p>\u4f60\u6bcf\u4e2a\u665a\u4e0a\u90fd\u4f1a\u5728\u540c\u4e00\u4e2a\u7267\u573a(\u8fd9\u662f\u4f9b\u4f60\u9009\u62e9\u7684)\u8fc7\u591c, \u76f4\u5230\u5976\u725b\u4eec\u90fd\u4ece\u60b2\u4f24\u4e2d\u7f13\u8fc7\u795e\u6765. \u5728\u65e9\u4e0a <br \/>\u8d77\u6765\u548c\u665a\u4e0a\u56de\u53bb\u7761\u89c9\u7684\u65f6\u5019, \u4f60\u90fd\u9700\u8981\u548c\u5728\u4f60\u7761\u89c9\u7684\u7267\u573a\u7684\u5976\u725b\u4ea4\u8c08\u4e00\u6b21. \u8fd9\u6837\u4f60\u624d\u80fd\u5b8c\u6210\u4f60\u7684 <br \/>\u4ea4\u8c08\u4efb\u52a1. <\/p>\n<p>\u5047\u8bbeFarmer John\u91c7\u7eb3\u4e86\u4f60\u7684\u5efa\u8bae, \u8bf7\u8ba1\u7b97\u51fa\u4f7f\u6240\u6709\u5976\u725b\u90fd\u88ab\u5b89\u6170\u7684\u6700\u5c11\u65f6\u95f4. <\/p>\n<p>\u5bf9\u4e8e\u4f60\u524d10\u6b21\u7684\u63d0\u4ea4, \u4f60\u7684\u7a0b\u5e8f\u4f1a\u5728\u4e00\u90e8\u5206\u6b63\u5f0f\u7684\u6d4b\u8bd5\u6570\u636e\u4e0a\u8fd0\u884c, \u5e76\u4e14\u8fd4\u56de\u8fd0\u884c\u7684\u7ed3\u679c. <\/p>\n<p>\u7a0b\u5e8f\u540d: cheer <\/p>\n<p><strong>Input <\/strong><\/p>\n<p>* \u7b2c 1 \u884c: \u7528\u7a7a\u683c\u9694\u5f00\u7684\u4e24\u4e2a\u6574\u6570N\u548cP <br \/>* \u7b2c 2..N+1 \u884c: \u7b2ci+1\u884c\u5305\u542b\u4e86\u4e00\u4e2a\u6574\u6570: C_i <br \/>* \u7b2c N+2..N+P+1 \u884c: \u7b2c N+j+1 \u884c\u5305\u542b\u7528\u7a7a\u683c\u9694\u5f00\u7684\u4e09\u4e2a\u6574\u6570: S_j, E_j \u548c L_j <\/p>\n<p><strong>Output <\/strong><\/p>\n<p>\u7b2c 1 \u884c: \u4e00\u4e2a\u6574\u6570, \u6240\u9700\u8981\u7684\u603b\u65f6\u95f4(\u5305\u542b\u548c\u5728\u4f60\u6240\u5728\u7684\u7267\u573a\u7684\u5976\u725b\u7684\u4e24\u6b21\u8c08\u8bdd\u65f6\u95f4). <\/p>\n<p><strong>Sample Input <\/strong><\/p>\n<\/p>\n<p><strong>Sample Output <\/strong><\/p>\n<\/p>\n<p><strong>Source <br \/>\u997f..\u8fd9\u9053\u9898\u8fd8\u662f\u6709\u70b9\u610f\u601d\u7684&#8230;\u9996\u5148\u8981\u6211\u4eec\u6c42\u4e00\u4e2a\u751f\u6210\u6811..\u90a3\u4e48\u5c1d\u8bd5\u7740\u8f6c\u5316\u6210\u6700\u5c0f\u751f\u6210\u6811\u95ee\u9898,\u5bf9\u4e8e\u6bcf\u6761\u8fb9,\u5982\u679c\u9009\u7684\u8bdd,\u5219\u8981\u8017\u53bb\u6765\u56de\u4e00\u8d9f\u548c\u8bbf\u95ee2\u4e2a\u7aef\u70b9\u7684\u65f6\u95f4,\u91cd\u52a0\u4e00\u4e0b\u6743\u5c31\u53ef\u4ee5\u4e86,\u6700\u540e\u9009\u62e9\u6700\u5c0f\u7684\u54ea\u4e2a\u8282\u70b9\u5f53\u51fa\u53d1\u70b9\u5c31\u884c\u4e86\u3002..<br \/>Code:<br \/><\/strong><\/p>\n<p>#include&lt;iostream&gt;#include&lt;cstdio&gt;#include&lt;algorithm&gt;#include&lt;queue&gt;#define rep(i,n) for(int i=0;i&lt;n;i++)using namespace std;const int maxn=10000;int n,m;struct uf{    int F[maxn];    uf(){rep(i,n)F[i]=i;}    int Find(int i)    {        return i==F[i]?i:(F[i]=Find(F[i]));    }    bool Find(int i,int j)    {        i=Find(i);j=Find(j);        return F[i]=j,i!=j;    }};struct Edge{    int s,t,c;    Edge(int _s,int _t,int _c):s(_s),t(_t),c(_c){}    bool operator&lt;(const Edge&amp;o)const    {        return c&gt;o.c;    }};priority_queue&lt;Edge&gt; PQ;int C[maxn];int main(){    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);    cin&gt;&gt;n&gt;&gt;m;int s,t,c,ans=~0U&gt;&gt;1;    rep(i,n)scanf(&quot;%d&quot;,C+i),ans&lt;?=C[i];    rep(i,m)scanf(&quot;%d%d%D&quot;,&amp;s,&amp;t,&amp;c),&#8211;s,&#8211;t,PQ.push(Edge(s,t,c*2+C[s]+C[t]));    uf U;    while(n&gt;1)    {        Edge e=PQ.top();PQ.pop();        if(U.Find(e.s,e.t))            ans+=e.c,n&#8211;;    }    cout&lt;&lt;ans&lt;&lt;endl;}176\u8f93\u51fa\u89e3\u91ca:\u4fdd\u6301\u8fd9\u4e9b\u8def\u5f84:     1-(5)-2-(5)-3      5                      \/         (12)        \/(12)             *4&#8212;&#8212;+\u4ece\u7267\u573a4\u8d77\u5e8a, \u7136\u540e\u6309\u7167 4, 5, 4, 2, 3, 2, 1, 2, 4 \u7684\u987a\u5e8f\u6765\u8bbf\u95ee\u5976\u725b\u4eec, \u603b\u5171\u9700\u8981176\u4e2a\u5355\u4f4d\u7684\u65f6\u95f4.5 71010206301 2 52 3 52 4 123 4 172 5 153 5 64 5 12\u8f93\u5165\u89e3\u91ca:              +-(15)-+             \/                    \/               1-(5)-2-(5)-3-(6)&#8211;5               \/(17)  \/         (12) \/      \/(12)              4&#8212;&#8212;+ <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Usaco2008Nov]\u5b89\u6170\u5976\u725bcheer Time Limit:10000MS Memory Limit:165536KTotal Submit:18 Accepted:15 Case Time Limit:1000MS Description Farmer John\u53d8\u5f97\u975e\u5e38\u61d2, \u4ed6\u4e0d\u60f3\u518d\u7ee7\u7eed\u7ef4\u62a4\u4f9b\u5976\u725b\u4e4b\u95f4\u4f9b\u901a\u884c\u7684\u9053\u8def. \u9053\u8def\u88ab\u7528\u6765\u8fde\u63a5N (5 &lt;= N &lt;= 10,000)\u4e2a\u7267\u573a, \u7267\u573a\u88ab\u8fde\u7eed\u5730\u7f16\u53f7\u4e3a1..N. \u6bcf\u4e00\u4e2a\u7267\u573a\u90fd\u662f\u4e00\u4e2a\u5976\u725b\u7684\u5bb6. FJ\u8ba1\u5212\u9664\u53bbP(N-1 &lt;= P &lt;= 100,000)\u6761\u9053\u8def\u4e2d\u5c3d\u53ef\u80fd\u591a\u7684\u9053\u8def, \u4f46\u662f\u8fd8\u8981\u4fdd\u6301\u7267\u573a\u4e4b\u95f4 \u7684\u8fde\u901a\u6027. \u4f60\u9996\u5148\u8981\u51b3\u5b9a\u90a3\u4e9b\u9053\u8def\u662f\u9700\u8981\u4fdd\u7559\u7684N-1\u6761\u9053\u8def. \u7b2cj\u6761\u53cc\u5411\u9053\u8def\u8fde\u63a5\u4e86\u7267\u573aS_j\u548cE_j (1 &lt;= S_j &lt;= N; 1 &lt;= E_j &lt;= N; S_j != E_j), \u800c\u4e14\u8d70\u5b8c\u5b83\u9700\u8981L_j (0 &lt;= L_j &lt;= 1,000)\u7684\u65f6\u95f4. \u6ca1\u6709\u4e24\u4e2a\u7267\u573a\u662f\u88ab\u4e00\u6761\u4ee5\u4e0a\u7684\u9053\u8def\u6240\u8fde\u63a5. \u5976\u725b\u4eec\u975e\u5e38\u4f24\u5fc3, \u56e0\u4e3a\u5979\u4eec\u7684\u4ea4\u901a\u7cfb\u7edf\u88ab\u524a\u51cf\u4e86. \u4f60\u9700\u8981\u5230\u6bcf\u4e00\u4e2a\u5976\u725b\u7684\u4f4f\u5904\u53bb\u5b89\u6170\u5979\u4eec. \u6bcf\u6b21 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/229"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}