{"id":500,"date":"2017-04-20T22:56:58","date_gmt":"2017-04-20T14:56:58","guid":{"rendered":"http:\/\/kylelv.com\/?p=500"},"modified":"2018-01-18T17:04:12","modified_gmt":"2018-01-18T09:04:12","slug":"bzoj-1433-zjoi2009%e5%81%87%e6%9c%9f%e7%9a%84%e5%ae%bf%e8%88%8d-%e6%9c%80%e5%a4%a7%e6%b5%81","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=500","title":{"rendered":"bzoj 1433: [ZJOI2009]\u5047\u671f\u7684\u5bbf\u820d  &#8212; \u6700\u5927\u6d41"},"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-69fdef757a503\" 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-69fdef757a503\"  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=500\/#1433_ZJOI2009%E5%81%87%E6%9C%9F%E7%9A%84%E5%AE%BF%E8%88%8D\" title=\"1433: [ZJOI2009]\u5047\u671f\u7684\u5bbf\u820d\">1433: [ZJOI2009]\u5047\u671f\u7684\u5bbf\u820d<\/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=500\/#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=500\/#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=500\/#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=500\/#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=500\/#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=500\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"1433_ZJOI2009%E5%81%87%E6%9C%9F%E7%9A%84%E5%AE%BF%E8%88%8D\"><\/span>1433: [ZJOI2009]\u5047\u671f\u7684\u5bbf\u820d<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\"><img decoding=\"async\" src=\"http:\/\/www.lydsy.com\/JudgeOnline\/images\/1432_1.jpg\" alt=\"\" border=\"0\" \/><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><img decoding=\"async\" src=\"http:\/\/www.lydsy.com\/JudgeOnline\/images\/1432_2.jpg\" alt=\"\" border=\"0\" \/><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\"><img decoding=\"async\" src=\"http:\/\/www.lydsy.com\/JudgeOnline\/images\/1432_3.jpg\" alt=\"\" border=\"0\" \/><\/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\">1<br \/>\n3<br \/>\n1 1 0<br \/>\n0 1 0<br \/>\n0 1 1<br \/>\n1 0 0<br \/>\n1 0 0<\/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\"><span class=\"sampledata\">\u02c6 \u02c6<br \/>\n<\/span><\/div>\n<h2><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"content\">\n<p>\u5bf9\u4e8e30% \u7684\u6570\u636e\u6ee1\u8db31 \u2264 n \u2264 12\u3002<br \/>\n\u5bf9\u4e8e100% \u7684\u6570\u636e\u6ee1\u8db31 \u2264 n \u2264 50,1 \u2264 T \u2264 20\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u6211\u4eec\u4ece\u6e90\u70b9\u5411\u6240\u6709\u4f4f\u5bbf\u7684\u4eba\u8fde\u8fb9\uff0c\u4ece\u6240\u6709\u7684\u5e8a\u4f4d\u8fde\u5411\u6c47\u70b9\uff0c\u7136\u540e\u518d\u4ece\u4eba\u8fde\u5411\u4ed6\u6240\u8ba4\u8bc6\u7684\u4eba\u7684\u5e8a\u4f4d<\/p>\n<p>\u8fd9\u6837\u5efa\u8fb9\uff0c\u7136\u540e\u8dd1\u6700\u5927\u6d41<\/p>\n<p>\u8fd9\u6837\u7b54\u6848\u5982\u679c\u548c\u4f4f\u5bbf\u4eba\u6570\u76f8\u7b49\u5219\u6ee1\u8db3\uff0c\u5426\u5219\u4e0d\u6ee1\u8db3<\/p>\n<pre class=\"lang:c++ decode:true \">#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 inf 100007\r\n#define F(i) for(i=1;i&lt;=n;i++)\r\n#define N 50010\r\n#define M 110\r\ninline int rd()\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 lj[M],fro[N],to[N],cnt,v[N],S,T=101;\r\ninline void add(int a,int b,int c){fro[++cnt]=lj[a];to[cnt]=b;v[cnt]=c;lj[a]=cnt;}\r\ninline void ins(int a,int b,int c){add(a,b,c);add(b,a,0);}\r\nint dis[M],q[N],h,t;\r\nbool bfs()\r\n{\r\n    memset(dis,0,sizeof(dis));\r\n    dis[0]=h=t=1;q[1]=0;\r\n    int tp;\r\n    while(h&lt;=t)\r\n    {\r\n        tp=q[h++];\r\n        for(int i=lj[tp];i;i=fro[i])\r\n        {\r\n            if(!dis[to[i]]&amp;&amp;v[i])\r\n            {\r\n                dis[to[i]]=dis[tp]+1;\r\n                q[++t]=to[i];\r\n            }\r\n        }\r\n    }\r\n    return dis[T]?1:0;\r\n}\r\nint dfs(int x,int p)\r\n{\r\n    if(x==T) return p;\r\n    int tp,res=0;\r\n    for(int i=lj[x];i;i=fro[i])\r\n    {\r\n        if(v[i]&amp;&amp;dis[to[i]]==dis[x]+1)\r\n        {\r\n            tp=dfs(to[i],min(p-res,v[i]));\r\n            v[i]-=tp; \r\n            v[i^1]+=tp;\r\n            res+=tp;\r\n            if(res==p) return p;\r\n        }\r\n    }\r\n    if(res==0)  dis[x]=0;\r\n    return res;\r\n}\r\nint n,tt,sc[M],tot,ans;\r\nint main()\r\n{\r\n    tt=rd();\r\n    int i,j,x;\r\n    while(tt--)\r\n    {\r\n        tot=ans=0;\r\n        memset(lj,0,sizeof(lj));cnt=1;\r\n        n=rd();\r\n        F(i){\r\n            sc[i]=rd();\r\n            if(sc[i]) ins(i+n,T,1);\r\n        }\r\n        F(i){\r\n            x=rd();\r\n            if((sc[i]&amp;&amp;!x)||!sc[i])\r\n            {\r\n                ins(0,i,1);\r\n                tot++;\r\n            }\r\n        }\r\n        F(i) F(j)\r\n        {\r\n            x=rd();\r\n            if(x||i==j) ins(i,j+n,1);\r\n        }\r\n        while(bfs()) ans+=dfs(0,inf);\r\n        if(tot==ans) puts(\"^_^\");\r\n        else puts(\"T_T\");\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1433: [ZJOI2009]\u5047\u671f\u7684\u5bbf\u820d Time Limit:\u00a010 Sec\u00a0\u00a0Memory [&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":[43],"class_list":["post-500","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-43"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/500","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=500"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":502,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/500\/revisions\/502"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}