{"id":606,"date":"2017-05-02T18:55:00","date_gmt":"2017-05-02T10:55:00","guid":{"rendered":"http:\/\/kylelv.com\/?p=606"},"modified":"2020-03-04T14:11:30","modified_gmt":"2020-03-04T06:11:30","slug":"bzoj-4874-%e7%ad%90%e5%ad%90%e6%94%be%e7%90%83","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=606","title":{"rendered":"bzoj 4874: \u7b50\u5b50\u653e\u7403"},"content":{"rendered":"\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-69fdef6cb875c\" 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-69fdef6cb875c\"  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=606\/#4874_%E7%AD%90%E5%AD%90%E6%94%BE%E7%90%83\" title=\"4874: \u7b50\u5b50\u653e\u7403\">4874: \u7b50\u5b50\u653e\u7403<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#HINT\" title=\"HINT\">HINT<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.kylelv.com\/?p=606\/#Source\" title=\"Source\">Source<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"4874_%E7%AD%90%E5%AD%90%E6%94%BE%E7%90%83\"><\/span>4874: \u7b50\u5b50\u653e\u7403<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-text-align-center\">Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memory Limit:&nbsp;256 MB<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5c0fN\u6700\u8fd1\u5728\u7814\u7a76NP\u5b8c\u5168\u95ee\u9898\uff0c\u5c0fO\u770b\u5c0fN\u7814\u7a76\u5f97\u70ed\u706b\u671d\u5929\uff0c\u4fbf\u7ed9\u4ed6\u51fa\u4e86\u4e00\u9053\u8fd9\u6837\u7684\u9898\u76ee\uff1a\u6709 n \u4e2a\u7403\uff0c\u7528\u6574\u6570 1 \u5230 n \u7f16\u53f7\u3002\u8fd8\u6709 m \u4e2a\u7b50\u5b50\uff0c\u7528\u6574\u65701\u5230m\u7f16\u53f7\u3002\u6bcf\u4e2a\u7403\u53ea\u80fd\u653e\u8fdb\u7279\u5b9a\u7684\u4e24\u4e2a\u7b50\u5b50\u4e4b\u4e00\uff0c\u7b2c i \u4e2a\u7403\u53ef\u4ee5\u653e\u8fdb\u7684\u7b50\u5b50\u8bb0\u4e3a Ai \u548c Bi \u3002\u6bcf\u4e2a\u7403\u90fd\u5fc5\u987b\u653e\u8fdb\u4e00\u4e2a\u7b50\u5b50\u4e2d\u3002\u5982\u679c\u4e00\u4e2a\u7b50\u5b50\u5185\u6709\u5947\u6570\u4e2a\u7403\uff0c\u90a3\u4e48\u6211\u4eec\u79f0\u8fd9\u6837\u7684\u7b50\u5b50\u4e3a\u534a\u7a7a\u7684\u3002\u6c42\u534a\u7a7a\u7684\u7b50\u5b50\u6700\u5c11\u6709\u591a\u5c11\u4e2a\u3002\u5c0fN\u770b\u5230\u9898\u76ee\u540e\u77ac\u95f4\u6ca1\u4e86\u601d\u8def\uff0c\u7ad9\u5728\u65c1\u8fb9\u770b\u70ed\u95f9\u7684\u5c0fI\u563f\u563f\u4e00\u7b11\uff1a&#8221;\u6c34\u9898\uff01&#8221;\u7136\u540e\u4e09\u8a00\u4e24\u8bed\u9053\u51fa\u4e86\u4e00\u4e2a\u591a\u9879\u5f0f\u7b97\u6cd5\u3002\u5c0fN\u77ac\u95f4\u5c31\u60ca\u5446\u4e86\uff0c\u4e09\u79d2\u949f\u540e\u4ed6\u56de\u8fc7\u795e\u6765\u4e00\u62cd\u684c\u5b50\uff1a&#8221;\u4e0d\u5bf9\uff01\u8fd9\u4e2a\u95ee\u9898\u663e\u7136\u662fNP\u5b8c\u5168\u95ee\u9898\uff0c\u4f60\u7b97\u6cd5\u80af\u5b9a\u6709\u9519\uff01&#8221;\u5c0fI\u6d45\u7b11\uff1a&#8221;\u6240\u4ee5\uff0c\u7b49\u6211\u9886\u56fe\u7075\u5956\u5427!&#8221;\u5c0fO\u53ea\u4f1a\u51fa\u9898\u4e0d\u4f1a\u505a\u9898\uff0c\u6240\u4ee5\u627e\u5230\u4e86\u4f60&#8211;\u8bf7\u4f60\u5bf9\u8fd9\u4e2a\u95ee\u9898\u8fdb\u884c\u63a2\u7a76\uff0c\u5e76\u5199\u4e00\u4e2a\u7a0b\u5e8f\u89e3\u51b3\u6b64\u9898\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u7b2c\u4e00\u884c\u4e24\u4e2a\u6574\u6570 n\uff0cm\u63a5\u4e0b\u6765 n \u884c\uff0c\u7b2c i + 1 \u884c\u6709\u4e24\u4e2a\u6574\u6570 Ai \uff0c Bi \uff0c\u8868\u793a\u7b2c i \u4e2a\u7403\u53ef\u4ee5\u653e\u7684\u4e24\u4e2a\u7b50\u5b50\u3002\u4fdd\u8bc1 Ai \u4e0d\u7b49\u4e8e Bi1 &lt;= n\uff0cm &lt;= 2 * 10^5\uff0c1 &lt;= Ai\uff0cBi &lt;= m<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u7b2c\u4e00\u884c\u4e00\u4e2a\u6574\u6570\u8868\u793a\u534a\u7a7a\u7684\u7b50\u5b50\u7684\u6700\u5c0f\u503c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>4 3<br>1 2<br>2 3<br>1 3<br>1 2<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>0<br>1\uff0c3 \u53f7\u7403\u90fd\u653e\u5728 1 \u53f7\u7b50\u5b50\uff0c2\uff0c4 \u53f7\u7403\u90fd\u653e\u5728 2 \u53f7\u7b50\u5b50\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5404\u4f4d\u4e0d\u59a8\u8003\u8651\u4e0b\uff0c\u5982\u679c\u8981\u6c42\u8f93\u51fa\u65b9\u6848\u5e94\u8be5\u600e\u4e48\u5199.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source\"><\/span>Source<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><\/p>\n\n\n\n<p>\u597d\u5de7\u5999\u7684\u601d\u7ef4\u9898<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u628a\u7b50\u5b50\u770b\u6210\u70b9\uff0c\u7403\u5f53\u8fb9&nbsp;<\/p>\n\n\n\n<p>\u7136\u540e\u6c42\u4e00\u4e0b\u8fde\u901a\u5757\uff0c\u542b\u5947\u6570\u6761\u8fb9\u7684\u8fde\u901a\u5757\u4e2a\u6570\u5373\u4e3a\u7b54\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;map>\n#include&lt;cmath>\n#include&lt;queue>\n#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;iostream>\n#include&lt;algorithm>\nusing namespace std;\n#define ll long long\n#define N 400010\ninline int read()\n{\n    int x=0,f=1;char ch=getchar();\n    while(ch&lt;'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}\n    while(ch>='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\n    return x*f;\n}\nint to&#91;N],lj&#91;N],fro&#91;N],cnt;\nvoid add(int a,int b){fro&#91;++cnt]=lj&#91;a];to&#91;cnt]=b;lj&#91;a]=cnt;}\nbool vs&#91;N];\nint dfs(int x)\n{\n    vs&#91;x]=1;int tp=0;\n    for(int i=lj&#91;x];i;i=fro&#91;i])\n    {\n        tp++;\n        if(!vs&#91;to&#91;i]]) tp+=dfs(to&#91;i]);\n    }\n    return tp;\n}\nint n,m,x,y,ans;\nint main()\n{\n    n=read();m=read();\n    for(int i=1;i&lt;=n;i++)\n    {\n        x=read();y=read();\n        add(x,y);add(y,x);\n    }\n    int tp;\n    for(int i=1;i&lt;=m;i++) if(!vs&#91;i])\n    {\n        tp=dfs(i)>>1;\n        if(tp&amp;1) ans++;\n    }\n    printf(\"%d\\n\",ans);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>4874: \u7b50\u5b50\u653e\u7403 Time Limit:&nbsp;10 Sec&nbsp;&nbsp;Memory 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":[65,25],"class_list":["post-606","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-dfs","tag-25"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/606","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=606"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/606\/revisions"}],"predecessor-version":[{"id":607,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/606\/revisions\/607"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}