{"id":1031,"date":"2014-10-15T01:09:24","date_gmt":"2014-10-14T17:09:24","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1031"},"modified":"2014-10-15T01:09:24","modified_gmt":"2014-10-14T17:09:24","slug":"bzoj-1927-sdoi2010%e6%98%9f%e9%99%85%e7%ab%9e%e9%80%9f","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/bzoj-1927-sdoi2010%e6%98%9f%e9%99%85%e7%ab%9e%e9%80%9f\/","title":{"rendered":"BZOJ 1927. [Sdoi2010]\u661f\u9645\u7ade\u901f"},"content":{"rendered":"<p><a href=\"http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1927\">http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1927<\/a><br \/>\n<a href=\"http:\/\/hi.baidu.com\/lydrainbowcat\/item\/96ade2bf64c221f363388eb9\">http:\/\/hi.baidu.com\/lydrainbowcat\/item\/96ade2bf64c221f363388eb9<\/a><\/p>\n<h3>Brief description: <\/h3>\n<p>\u7565\u3002\uff09<\/p>\n<h3>Analysis: <\/h3>\n<p>\u8d39\u7528\u6d41\uff0c\u6700\u5c0f\u8def\u5f84\u8986\u76d6\u3002\uff09<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nint n, m;\r\n\r\nnamespace MinCostMaxFlow{\r\n\r\n    const int N = 2048, M = 2*N*N + 9;\r\n    const int NN = 2047; \/\/ cover_bit(N) - 1\r\n\r\n    int D&#x5B;N], hd&#x5B;N], suc&#x5B;M], to&#x5B;M], cap&#x5B;M], cst&#x5B;M];\r\n    int n, m, s, t; LL nesf, flow, cost;\r\n\r\n    int new_node(){\r\n        hd&#x5B;n] = 0;\r\n        return n++;\r\n    }\r\n\r\n    inline void add_edge(int x, int y, int c, int w = 0){\r\n        suc&#x5B;m] = hd&#x5B;x], to&#x5B;m] = y, cap&#x5B;m] = c, cst&#x5B;m] =  w, hd&#x5B;x] = m++;\r\n        suc&#x5B;m] = hd&#x5B;y], to&#x5B;m] = x, cap&#x5B;m] = 0, cst&#x5B;m] = -w, hd&#x5B;y] = m++;\r\n        \/\/nesf += w;\r\n    }\r\n\r\n    inline void add_edgee(int x, int y, int c, int w = 0){\r\n        add_edge(x, y, c, w);\r\n        add_edge(y, x, c, w);\r\n    }\r\n\r\n    int Q&#x5B;NN+1], pre&#x5B;N], cz, op; bool inQ&#x5B;N];\r\n\r\n#define v to&#x5B;i]\r\n#define c cap&#x5B;i]\r\n#define f cap&#x5B;i^1]\r\n#define w cst&#x5B;i]\r\n\r\n    bool spfa(){\r\n        fill(inQ, inQ+n, 0), fill(D, D+n, INF);\r\n        cz = 0, op = 1; D&#x5B;Q&#x5B;cz] = s] = 0; while (cz != op){\r\n            int u = Q&#x5B;cz++]; inQ&#x5B;u] = 0; cz &amp;= NN;\r\n            REP_G(i, u) if (c &amp;&amp; checkMin(D&#x5B;v], D&#x5B;u]+w)){\r\n                pre&#x5B;v] = i; if (!inQ&#x5B;v]) Q&#x5B;op++] = v, inQ&#x5B;v] = 1, op &amp;= NN;\r\n            }\r\n        }\r\n        return D&#x5B;t] != INF;\r\n    }\r\n\r\n#undef v\r\n\r\n    void add_path(){\r\n        int d = INF; int u, v = t; do{\r\n            int i = pre&#x5B;v]; checkMin(d, c);\r\n            u = to&#x5B;i^1], v = u;\r\n        } while (u != s);\r\n\r\n        flow += d; u, v = t; do{\r\n            int i = pre&#x5B;v]; f += d, c -= d; cost += d*w;\r\n            u = to&#x5B;i^1], v = u;\r\n        } while (u != s);\r\n    }\r\n\r\n    pair&lt;LL, LL&gt; Run(){\r\n        cost = 0, flow = 0; while (spfa()) add_path();\r\n        return MP(cost, flow);\r\n    }\r\n\r\n\r\n#undef c\r\n#undef f\r\n#undef w\r\n\r\n    void Init(){\r\n\r\n        RST(hd); m = 2; RD(::n, ::m); s = 0, t = 2*::n+1; n = t+1;\r\n\r\n        REP_1(i, ::n){\r\n            add_edge(s, ::n+i, 1, RD());\r\n            add_edge(s, i, 1, 0);\r\n            add_edge(::n+i, t, 1, 0);\r\n        }\r\n\r\n        DO(::m){\r\n            int x, y, w; RD(x, y, w); if (x &gt; y) swap(x, y);\r\n            add_edge(x, y+::n, 1, w);\r\n        }\r\n    }\r\n} \/\/using namespace MinCostMaxFlow;\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n\r\n    MinCostMaxFlow::Init();\r\n    cout &lt;&lt; MinCostMaxFlow::Run().fi &lt;&lt; endl;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1927 http:\/\/hi.baidu.com\/lydrainbowcat\/item\/96ade2bf64c221f363388eb9 Brief description: \u7565\u3002\uff09 Analysis: \u8d39\u7528\u6d41\uff0c\u6700\u5c0f\u8def\u5f84\u8986\u76d6\u3002\uff09 \/\/}\/* &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;. *\/ int n, m; namespace MinCostMaxFlow{ const int N = 2048, M = 2*N*N + 9; const int NN = 2047; \/\/ cover_bit(N) &#8211; 1 int D&#x5B;N], hd&#x5B;N], suc&#x5B;M], to&#x5B;M], cap&#x5B;M], cst&#x5B;M]; int n, m, s, t; LL nesf, flow, cost; int new_node(){ hd&#x5B;n] = 0; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-1031","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-gD","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=1031"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1031\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}