{"id":457,"date":"2012-09-07T04:25:27","date_gmt":"2012-09-06T20:25:27","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=457"},"modified":"2015-07-17T11:26:32","modified_gmt":"2015-07-17T03:26:32","slug":"bzoj-1497-noi2006%e6%9c%80%e5%a4%a7%e8%8e%b7%e5%88%a9","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/bzoj-1497-noi2006%e6%9c%80%e5%a4%a7%e8%8e%b7%e5%88%a9\/","title":{"rendered":"BZOJ 1497. [NOI2006]\u6700\u5927\u83b7\u5229"},"content":{"rendered":"<h3>Brief description: <\/h3>\n<p>&#8230;<\/p>\n<p><!--more--><\/p>\n<h3>Analysis: <\/h3>\n<p>Tags: \u6700\u5927\u6743\u95ed\u5408\u5b50\u56fe<br \/>\n&#8230; \u6bcf\u4e2a\u7b80\u5355\u5272\u5bf9\u5e94\u4e00\u4e2a\u95ed\u5408\u5b50\u56fe\u3002(\u6ca1\u6709\u9009\u4e2d\u7684\u6b63\u6743\u70b9 + \u9009\u4e2d\u7684\u8d1f\u6743\u70b9\u3002\u3002\u3002<br \/>\n<a href=\"http:\/\/paste.ubuntu.com\/1189601\/\"> Dinitz .. ( 700+ \/ 200+<\/a><br \/>\n\u3002(\u3002\u3002\u636e\u8bf4\u6362\u4e00\u79cd\u7b49\u4ef7\u5efa\u56fe\u53ef\u4ee5\u83b7\u5f97\u8c1c\u306e\u4f18\u5316\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\nconst int _N = 5009, _M = 50009;\r\nconst int N = _N + _M + 9, M = 2 * (N + _M * 3) + 9;\r\n\r\nint D&#x5B;N], hd&#x5B;N], suc&#x5B;M], to&#x5B;M], cap&#x5B;M];\r\nint n, m, s, t;\r\n\r\ninline void add_edge(int x, int y, int c){\r\n    suc&#x5B;m] = hd&#x5B;x], to&#x5B;m] = y, cap&#x5B;m] = c, hd&#x5B;x] = m++;\r\n    suc&#x5B;m] = hd&#x5B;y], to&#x5B;m] = x, cap&#x5B;m] = 0, hd&#x5B;y] = m++;\r\n}\r\n\r\ninline void add_edgee(int x, int y, int c){\r\n    suc&#x5B;m] = hd&#x5B;x], to&#x5B;m] = y, cap&#x5B;m] = c, hd&#x5B;x] = m++;\r\n    suc&#x5B;m] = hd&#x5B;y], to&#x5B;m] = x, cap&#x5B;m] = c, hd&#x5B;y] = m++;\r\n}\r\n\r\n#define v to&#x5B;i]\r\n#define c cap&#x5B;i]\r\n#define r cap&#x5B;i^1]\r\n\r\nbool bfs(){\r\n    static int Q&#x5B;N]; int cz = 0, op = 1;\r\n    fill(D, D+n, 0), D&#x5B;Q&#x5B;0] = s] = 1; while (cz &lt; op){\r\n        int u = Q&#x5B;cz++]; REP_G(i, u) if (!D&#x5B;v] &amp;&amp; c){\r\n            D&#x5B;Q&#x5B;op++] = v] = D&#x5B;u] + 1;\r\n            if (v == t) return 1;\r\n        }\r\n    }\r\n    return 0;\r\n}\r\n\r\nint Dinitz(){\r\n\r\n    assert(to&#x5B;0] == s);\r\n\r\n    int max_flow = 0; while (bfs()){\r\n\r\n        static int sta&#x5B;N], cur&#x5B;N]; int top = 0;\r\n        sta&#x5B;0] = 0, cur&#x5B;s] = hd&#x5B;s]; while (top != -1){\r\n\r\n            int u = to&#x5B;sta&#x5B;top]], i; if (u == t){\r\n                int d = INF; REP_1(ii, top) i = sta&#x5B;ii], checkMin(d, c); max_flow += d;\r\n                DWN_1(ii, top, 1){i = sta&#x5B;ii], c -= d, r += d; if (!c) top = ii - 1;}\r\n                u =to&#x5B;sta&#x5B;top]];\r\n            }\r\n\r\n            for (i=cur&#x5B;u];i;i=suc&#x5B;i])\r\n                if (D&#x5B;u] + 1 == D&#x5B;v] &amp;&amp; c) break;\r\n\r\n            if (!i) D&#x5B;u] = 0, --top;\r\n            else {\r\n                cur&#x5B;u] = suc&#x5B;i], cur&#x5B;v] = hd&#x5B;v];\r\n                sta&#x5B;++top] = i;\r\n            }\r\n        }\r\n    }\r\n    return max_flow;\r\n}\r\n\r\n#undef r\r\n#undef c\r\n\r\nint Sum;\r\n\r\nvoid init(){\r\n    int _n, _m; RD(_n, _m), m = 2 , t = _n+_m+1, n = t+1;\r\n    \/\/fill(hd, hd+n, 0); Sum = 0;\r\n    REP_1(i, _n) add_edge(s, i, RD());\r\n    REP_1(i, _m){\r\n        int x, y, z; RD(x, y, z); Sum += z;\r\n        add_edge(_n+i, t, z);\r\n        add_edge(x, _n+i, INF);\r\n        add_edge(y, _n+i, INF);\r\n    }\r\n}\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    init(); OT(Sum - Dinitz());\r\n}\r\n\r\n<\/pre>\n<h3>External link: <\/h3>\n<p><a href=\"http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1497\">http:\/\/www.lydsy.com\/JudgeOnline\/problem.php?id=1497<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description: &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[22],"tags":[89],"class_list":["post-457","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-89"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-7n","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/457","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=457"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}