{"id":430,"date":"2017-04-12T07:32:54","date_gmt":"2017-04-11T23:32:54","guid":{"rendered":"http:\/\/kylelv.com\/?p=430"},"modified":"2018-01-03T18:12:26","modified_gmt":"2018-01-03T10:12:26","slug":"bzoj-1143-ctsc2008%e7%a5%ad%e7%a5%80river-2718-violet-4%e6%af%95%e4%b8%9a%e6%97%85%e8%a1%8c-%e4%ba%8c%e5%88%86%e5%9b%be%e5%8c%b9%e9%85%8d","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=430","title":{"rendered":"bzoj 1143: [CTSC2008]\u796d\u7940river \/ 2718: [Violet 4]\u6bd5\u4e1a\u65c5\u884c  &#8212; \u4e8c\u5206\u56fe\u5339\u914d"},"content":{"rendered":"<p>&nbsp;<\/p>\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-69fdef6d33aa3\" 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-69fdef6d33aa3\"  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=430\/#1143_CTSC2008%E7%A5%AD%E7%A5%80river\" title=\"1143: [CTSC2008]\u796d\u7940river\">1143: [CTSC2008]\u796d\u7940river<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.kylelv.com\/?p=430\/#Description\" title=\"Description\">Description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.kylelv.com\/?p=430\/#Input\" title=\"Input\">Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.kylelv.com\/?p=430\/#Output\" title=\"Output\">Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.kylelv.com\/?p=430\/#Sample_Input\" title=\"Sample Input\">Sample Input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.kylelv.com\/?p=430\/#Sample_Output\" title=\"Sample Output\">Sample Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.kylelv.com\/?p=430\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1143_CTSC2008%E7%A5%AD%E7%A5%80river\"><\/span>1143: [CTSC2008]\u796d\u7940river<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: center;\"><span class=\"green\">Time Limit:\u00a010 Sec\u00a0\u00a0Memory Limit:\u00a0162 MB<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u3000\u3000\u5728\u9065\u8fdc\u7684\u4e1c\u65b9\uff0c\u6709\u4e00\u4e2a\u795e\u79d8\u7684\u6c11\u65cf\uff0c\u81ea\u79f0Y\u65cf\u3002\u4ed6\u4eec\u4e16\u4ee3\u5c45\u4f4f\u5728\u6c34\u9762\u4e0a\uff0c\u5949\u9f99\u738b\u4e3a\u795e\u3002\u6bcf\u9022\u91cd\u5927\u5e86\u5178\uff0c Y\u65cf\u90fd<\/div>\n<div>\u4f1a\u5728\u6c34\u9762\u4e0a\u4e3e\u529e\u76db\u5927\u7684\u796d\u7940\u6d3b\u52a8\u3002\u6211\u4eec\u53ef\u4ee5\u628aY\u65cf\u5c45\u4f4f\u5730\u6c34\u7cfb\u770b\u6210\u4e00\u4e2a\u7531\u5c94\u53e3\u548c\u6cb3\u9053\u7ec4\u6210\u7684\u7f51\u7edc\u3002\u6bcf\u6761\u6cb3\u9053\u8fde\u63a5\u7740<\/div>\n<div>\u4e24\u4e2a\u5c94\u53e3\uff0c\u5e76\u4e14\u6c34\u5728\u6cb3\u9053\u5185\u6309\u7167\u4e00\u4e2a\u56fa\u5b9a\u7684\u65b9\u5411\u6d41\u52a8\u3002\u663e\u7136\uff0c\u6c34\u7cfb\u4e2d\u4e0d\u4f1a\u6709\u73af\u6d41\uff08\u4e0b\u56fe\u63cf\u8ff0\u4e00\u4e2a\u73af\u6d41\u7684\u4f8b\u5b50\uff09\u3002<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/www.lydsy.com\/JudgeOnline\/images\/1143.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<div>\u3000\u3000\u7531\u4e8e\u4eba\u6570\u4f17\u591a\u7684\u539f\u56e0\uff0cY\u65cf\u7684\u796d\u7940\u6d3b\u52a8\u4f1a\u5728\u591a\u4e2a\u5c94\u53e3\u4e0a\u540c\u65f6\u4e3e\u884c\u3002\u51fa\u4e8e\u5bf9\u9f99\u738b\u7684\u5c0a\u91cd\uff0c\u8fd9\u4e9b\u796d\u7940\u5730\u70b9\u7684\u9009\u62e9\u5fc5<\/div>\n<div>\u987b\u975e\u5e38\u614e\u91cd\u3002\u51c6\u786e\u5730\u8bf4\uff0cY\u65cf\u4eba\u8ba4\u4e3a\uff0c\u5982\u679c\u6c34\u6d41\u53ef\u4ee5\u4ece\u4e00\u4e2a\u796d\u7940\u70b9\u6d41\u5230\u53e6\u5916\u4e00\u4e2a\u796d\u7940\u70b9\uff0c\u90a3\u4e48\u796d\u7940\u5c31\u4f1a\u5931\u53bb\u5b83\u795e\u5723<\/div>\n<div>\u7684\u610f\u4e49\u3002\u65cf\u957f\u5e0c\u671b\u5728\u4fdd\u6301\u796d\u7940\u795e\u5723\u6027\u7684\u57fa\u7840\u4e0a\uff0c\u9009\u62e9\u5c3d\u53ef\u80fd\u591a\u7684\u796d\u7940\u7684\u5730\u70b9\u3002<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<div>\u3000\u3000\u7b2c\u4e00\u884c\u5305\u542b\u4e24\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570N\u3001M\uff0c\u5206\u522b\u8868\u793a\u5c94\u53e3\u548c\u6cb3\u9053\u7684\u6570\u76ee\uff0c\u5c94\u53e3\u4ece1\u5230N\u7f16\u53f7\u3002\u63a5\u4e0b\u6765M\u884c\uff0c\u6bcf\u884c\u5305<\/div>\n<p>&nbsp;<\/p>\n<div>\u542b\u4e24\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570u\u3001v\uff0c\u63cf\u8ff0\u4e00\u6761\u8fde\u63a5\u5c94\u53e3u\u548c\u5c94\u53e3v\u7684\u6cb3\u9053\uff0c\u6c34\u6d41\u65b9\u5411\u4e3a\u81eau\u5411v\u3002 N \u2264 100 M \u2264 1 000<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u3000\u3000\u7b2c\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u6574\u6570K\uff0c\u8868\u793a\u6700\u591a\u80fd\u9009\u53d6\u7684\u796d\u7940\u70b9\u7684\u4e2a\u6570\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><span class=\"sampledata\">4 4<br \/>\n1 2<br \/>\n3 4<br \/>\n3 2<br \/>\n4 2<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p><span class=\"sampledata\">2<\/span><\/p>\n<p>\u3010\u6837\u4f8b\u8bf4\u660e\u3011<br \/>\n\u5728\u6837\u4f8b\u7ed9\u51fa\u7684\u6c34\u7cfb\u4e2d\uff0c\u4e0d\u5b58\u5728\u4e00\u79cd\u65b9\u6cd5\u80fd\u591f\u9009\u62e9\u4e09\u4e2a\u6216\u8005\u4e09\u4e2a\u4ee5\u4e0a\u7684\u796d\u7940\u70b9\u3002\u5305\u542b\u4e24\u4e2a\u796d\u7940\u70b9\u7684\u6d4b\u8bd5\u70b9\u7684\u65b9\u6848\u6709\u4e24\u79cd\uff1a<br \/>\n\u9009\u62e9\u5c94\u53e31\u4e0e\u5c94\u53e33\uff08\u5982\u6837\u4f8b\u8f93\u51fa\u7b2c\u4e8c\u884c\uff09\uff0c\u9009\u62e9\u5c94\u53e31\u4e0e\u5c94\u53e34\u3002<br \/>\n\u6c34\u6d41\u53ef\u4ee5\u4ece\u4efb\u610f\u5c94\u53e3\u6d41\u81f3\u5c94\u53e32\u3002\u5982\u679c\u5728\u5c94\u53e32\u5efa\u7acb\u796d\u7940\u70b9\uff0c\u90a3\u4e48\u4efb\u610f\u5176\u4ed6\u5c94\u53e3\u90fd\u4e0d\u80fd\u5efa\u7acb\u796d\u7940\u70b9<br \/>\n\u4f46\u662f\u5728\u6700\u4f18\u7684\u4e00\u79cd\u796d\u7940\u70b9\u7684\u9009\u53d6\u65b9\u6848\u4e2d\u6211\u4eec\u53ef\u4ee5\u5efa\u7acb\u4e24\u4e2a\u796d\u7940\u70b9\uff0c\u6240\u4ee5\u5c94\u53e32\u4e0d\u80fd\u5efa\u7acb\u796d\u7940\u70b9\u3002\u5bf9\u4e8e\u5176\u4ed6\u5c94\u53e3<br \/>\n\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u6700\u4f18\u65b9\u6848\u9009\u62e9\u8be5\u5c94\u53e3\u4e3a\u796d\u7940\u70b9\uff0c\u6240\u4ee5\u8f93\u51fa\u4e3a1011\u3002<\/p>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5148floyd\u4f20\u9012\u95ed\u5305\uff0c\u518d\u6c42\u6700\u5c0f\u8def\u5f84\u8986\u76d6<\/p>\n<p>\u5e38\u7528\u5b9a\u7406\uff1a<br \/>\n<strong>\u3000\u3000\u6700\u5c0f\u70b9\u8986\u76d6=\u6700\u5927\u5339\u914d\u3002<\/strong><br \/>\n<strong>\u3000\u3000\u6700\u5c0f\u8fb9\u8986\u76d6=\u6700\u5927\u72ec\u7acb\u96c6=\u56fe\u4e2d\u70b9\u7684\u4e2a\u6570-\u6700\u5927\u5339\u914d\u3002<\/strong><br \/>\n<strong>\u3000\u3000\u6700\u957f\u53cd\u94fe=\u6700\u5c0f\u8def\u5f84\u8986\u76d6=\u539f\u56fe\u7684\u8282\u70b9\u6570-\u65b0\u56fe\u6700\u5927\u5339\u914d\u3002<\/strong><\/p>\n<pre class=\"lang:c++ decode:true \">#include&lt;map&gt;\r\n#include&lt;cmath&gt;\r\n#include&lt;queue&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;cstring&gt;\r\n#include&lt;iostream&gt;\r\n#include&lt;algorithm&gt;\r\nusing namespace std;\r\n#define ll long long\r\n#define N 210\r\ninline int read()\r\n{\r\n    int x=0,f=1;char ch=getchar();\r\n    while(ch&lt;'0'||ch&gt;'9'){if(ch=='-')f=-1;ch=getchar();}\r\n    while(ch&gt;='0'&amp;&amp;ch&lt;='9'){x=x*10+ch-'0';ch=getchar();}\r\n    return x*f;\r\n}\r\nint n,m,pp[N],dis[N],u,v,ans,tim;\r\nbool mp[N][N];\r\nbool dfs(int x)\r\n{\r\n    for(int i=1;i&lt;=n;i++) if(mp[x][i])\r\n    {\r\n        if(dis[i]==tim) continue;\r\n        dis[i]=tim;\r\n        if(!pp[i]||dfs(pp[i])){pp[i]=x;return 1;}\r\n    }\r\n    return 0;\r\n}\r\nint main()\r\n{\r\n    n=read();m=read();\r\n    for(int i=1;i&lt;=m;i++)\r\n    {\r\n        u=read();v=read();\r\n        mp[u][v]=1;\r\n    }\r\n    for(int k=1;k&lt;=n;k++)\r\n    for(int i=1;i&lt;=n;i++)\r\n    for(int j=1;j&lt;=n;j++)\r\n        mp[i][j]|=mp[i][k]&amp;mp[k][j];\r\n    ans=n;\r\n    for(int i=1;i&lt;=n;i++) tim++,ans-=dfs(i);\r\n    printf(\"%d\\n\",ans);\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1143: [CTSC2008]\u796d\u7940river Time Limit:\u00a010 Sec\u00a0\u00a0Memo [&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":[12],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-12"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/430","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=430"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":432,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions\/432"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}