{"id":675,"date":"2013-02-02T16:24:36","date_gmt":"2013-02-02T08:24:36","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=675"},"modified":"2013-02-02T18:55:13","modified_gmt":"2013-02-02T10:55:13","slug":"facebook-hacker-cup-2012-round-2","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/facebook-hacker-cup-2012-round-2\/","title":{"rendered":"Facebook Hacker Cup 2012 Round 2"},"content":{"rendered":"<h3>External link: <\/h3>\n<p><a href=\"https:\/\/www.facebook.com\/hackercup\/problems.php?pid=182208915220500&#038;round=222291111185610\">https:\/\/www.facebook.com\/hackercup\/problems.php?pid=182208915220500&#038;round=222291111185610<\/a><br \/>\n<a href=\"http:\/\/codeforces.com\/gym\/100159\">http:\/\/codeforces.com\/gym\/100159<\/a><\/p>\n<p><!--more--><\/p>\n<h2>Problem A. Monopoly<\/h2>\n<h3>Brief description: <\/h3>\n<p>.. \u7ed9\u5b9a n \u4e2a\u7ed3\u70b9\u3002\u3002\u8ba9\u4f60\u6309\u7167\u7ed9\u5b9a\u7684\u987a\u5e8f\u5408\u5e76 n-1 \u6b21\u53d8\u6210\u4e00\u9897\u6811\u3002\u3002\u7531\u4f60\u51b3\u5b9a\u6bcf\u6b21\u5408\u5e76\u65f6\u3002\u8c01\u4f5c\u4e3a\u7236\u4eb2\u3002\u3002\u3002<br \/>\n\u3002\u3002\u4f7f\u5f97\u6bcf\u4e2a\u7ed3\u70b9\u7684\u5b69\u5b50\u4e0d\u8d85\u8fc7 M \u4e2a\u3002\u3002\u3002\u5e76\u4e14\u9ad8\u5ea6\u6700\u5c0f\u3002\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>&#8230; \u7528\u5e76\u67e5\u96c6\u6a21\u62df\u5373\u53ef\u3002\u3002\u6bcf\u6b21\u5408\u5e76\u7684\u65f6\u5019\u7ef4\u62a4\u6240\u6709\u7684\u5408\u6cd5\u65b9\u6848\u5373\u53ef\u3002\u3002<br \/>\n\uff08\u3002\u3002\u5373\u5f00\u4e00\u4e2a vector<PII> \u3002\u3002(\u9ad8\u5ea6, \u5bbd\u5ea6\uff09\u3002\u3002\u9ad8\u5ea6\u9012\u589e\u3002\u3002\u5bbd\u5ea6\u9012\u51cf\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = 32768;\r\n\r\nnamespace dsu{\r\n    int p&#x5B;N]; VII c&#x5B;N];\r\n    int n, m;\r\n\r\n    int Find(int x){\r\n        return x == p&#x5B;x] ? x : p&#x5B;x] = Find(p&#x5B;x]);\r\n    }\r\n\r\n    void Union(int x, int y){\r\n        x = Find(x), y = Find(y); VII cc;\r\n        int h = c&#x5B;y]&#x5B;0].fi+1; ECH(it, c&#x5B;x]) if (it-&gt;se&lt;m) cc.PB(MP(max(it-&gt;fi, h), it-&gt;se+1));\r\n        h = c&#x5B;x]&#x5B;0].fi+1; ECH(it, c&#x5B;y]) if (it-&gt;se&lt;m) cc.PB(MP(max(it-&gt;fi, h), it-&gt;se+1));\r\n        SRT(cc), p&#x5B;y] = x; CLR(c&#x5B;x]); ECH(it, cc) if (c&#x5B;x].empty() || it-&gt;se &lt; c&#x5B;x].back().se) c&#x5B;x].PB(*it);\r\n    }\r\n\r\n    void gao(){\r\n        DO(n-1) Union(RD(), RD());\r\n    }\r\n\r\n    void init(){\r\n        RD(n, m); REP_1(i, n) p&#x5B;i] = i, CLR(c&#x5B;i]), c&#x5B;i].PB(MP(1, 0));\r\n    }\r\n} using namespace dsu;\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    Rush{\r\n        init(), gao();\r\n        OT(c&#x5B;Find(1)].front().fi);\r\n    }\r\n}\r\n<\/pre>\n<h2>Problem B. Road Removal<\/h2>\n<h3>Brief description: <\/h3>\n<p>.\u65e0\u5411\u56fe\u3002\u3002n \u4e2a\u7ed3\u70b9 m \u6761\u8fb9\u3002\u3002\u524d k \u4e2a\u7ed3\u70b9\u662f\u5173\u952e\u7ed3\u70b9\u3002\u3002<br \/>\n\u3002\u3002\u8981\u6c42\u5220\u9664\u6700\u5c11\u6570\u636e\u7684\u8fb9\u4f7f\u5f97\u73af\u4e0d\u4f1a involve \u5173\u952e\u7ed3\u70b9\u3002\u3002\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>&#8230;\u3002\u3002\u5c45\u7136\u8fd8\u662f\u5e76\u67e5\u96c6\u3002\u3002\uff08\uff1f\u3002\u3002<br \/>\n\u5148\u628a\u6240\u6709\u5b89\u5168\u8fb9\u5168\u90e8\u7528\u4e0a\u3002\u3002\uff08\u4e0d\u4e0e\u5173\u952e\u70b9\u76f8\u5173\u7684\u8fb9\u3002\u3002<br \/>\n\u3002\u3002\u3002\u518d\u770b\u975e\u5b89\u5168\u8fb9\u80fd\u4e0d\u80fd\u5408\u5e76\u5373\u53ef\u3002\u3002\u3002<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(1e4) + 9, M = int(5e4) + 9;\r\n\r\nnamespace dsu{\r\n    int p&#x5B;N], r&#x5B;N], n, m, k, res;\r\n    int a&#x5B;M], b&#x5B;M];\r\n\r\n    void Make(int x){\r\n        r&#x5B;x] = 0, p&#x5B;x] = x;\r\n    }\r\n\r\n    int Find(int x){\r\n        return x == p&#x5B;x] ? x : p&#x5B;x] = Find(p&#x5B;x]);\r\n    }\r\n\r\n    bool Union(int x, int y){\r\n        x = Find(x), y = Find(y);\r\n        if (x == y) return false;\r\n        if (r&#x5B;x] &lt; r&#x5B;y]) p&#x5B;x] = y;\r\n        else {\r\n            if (r&#x5B;x] == r&#x5B;y]) ++r&#x5B;x];\r\n            p&#x5B;y] = x;\r\n        }\r\n        return true;\r\n    }\r\n\r\n    void gao(){\r\n        REP(i, m){\r\n            RD(a&#x5B;i], b&#x5B;i]); if (a&#x5B;i] &gt;= k &amp;&amp; b&#x5B;i] &gt;= k) Union(a&#x5B;i], b&#x5B;i]);\r\n            else ++res;\r\n        }\r\n\r\n        REP(i, m) res -= Union(a&#x5B;i], b&#x5B;i]);\r\n    }\r\n\r\n    void init(){\r\n        RD(n, m, k); REP(i, n) Make(i);\r\n        res = 0;\r\n    }\r\n} using namespace dsu;\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    Rush{\r\n        init(); gao();\r\n        OT(res);\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>External link: https:\/\/www.facebook.com\/hackercup\/problems.php?pid=182208915220500&#038;round=222291111185610 http:\/\/codeforces.com\/gym\/100159<\/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":[109],"tags":[],"class_list":["post-675","post","type-post","status-publish","format-standard","hentry","category-facebook-hacker-cup"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-aT","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/675","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=675"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/675\/revisions"}],"predecessor-version":[{"id":676,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/675\/revisions\/676"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}