{"id":327,"date":"2010-07-29T17:50:00","date_gmt":"2010-07-29T09:50:00","guid":{"rendered":"http:\/\/localhost\/?p=327"},"modified":"2010-07-29T17:50:00","modified_gmt":"2010-07-29T09:50:00","slug":"codeforces19_e","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=327","title":{"rendered":"CodeForces#19 E"},"content":{"rendered":"<p> \u8fd9\u662f\u9053\u597d\u9898\u554a\u3002\u3002\u3002\u60f3\u60f3\u9ebb\u70e6\u3002\u3002\u505a\u505a\u66f4\u9ebb\u70e6\u3002\u3002<br \/>\u9898\u76ee\u5f88\u7b80\u6d01\uff0c\u7ed9\u4f60\u4e00\u4e2a\u56fe\uff0c\u6c42\u54ea\u4e9b\u8fb9\u5220\u6389\u4e4b\u540e\u80fd\u53d8\u6210\u4e8c\u5206\u56fe\u3002\u3002<br \/>\u989d\u3002\u3002\u6211WA\u4e86N\u6b21\u3002\u3002\u6bd4\u8d5b\u7684\u65f6\u5019\u80af\u5b9a\u6765\u4e0d\u53ca\u3002\u3002\u3002<br \/>\u6162\u6162\u5206\u6790\u5427\u3002\u3002<br \/>\u9996\u5148\u6c42\u751f\u6210\u6811\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u70b92-\u67d3\u8272\uff0c<br \/>\u90a3\u4e48\u5982\u679c\u5220\u975e\u6811\u8fb9\u7684\u8bdd\uff0c\u663e\u7136\u4efb\u4f55\u70b9\u7684\u989c\u8272\u90fd\u4e0d\u4f1a\u53d8\uff0c\u90a3\u4e48\u5982\u679c\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u67090\u6761\uff0c\u6240\u6709\u975e\u6811\u8fb9\u90fd\u53ef\u4ee5\u5220\uff0c\u67091\u6761\uff0c\u53ea\u6709\u8fd9\u6761\u53ef\u4ee5\u5220\uff0c2\u6761\u6216\u4ee5\u4e0a\uff0c\u90fd\u4e0d\u80fd\u5220\u3002\u3002<br \/>\u5982\u679c\u5220\u6811\u8fb9\u7684\u8bdd\uff0c\u663e\u7136\u5fc5\u987b\u8981\u641e\u7ffb\u6240\u6709\u7684\u5947\u73af\uff0c\u5206\u6790\u4e00\u4e0b\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4e00\u4e2a\u6811\u4e2d\u4f1a\u51fa\u73b0\u5947\u73af\u3002\u3002<br \/>\u67d0\u4e2a\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u9020\u6210\u7684\u5947\u73af\u3002\u3002<br \/>\u4e00\u4e2a\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u548c\u4e00\u4e2a\u4e24\u7aef\u4e0d\u4e00\u6837\u7684\u975e\u6811\u8fb9\u9020\u6210\u7684\u5947\u73af\u3002\u3002<br \/>\u90a3\u4e48\u628a\u8fd9\u4e2a\u6811\u6811\u94fe\u5256\u5206\u4e00\u4e0b\u3002\u3002\u5bf9\u6bcf\u4e2a\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u4e4b\u95f4\u7684\u8def\u5f84+1\uff0c\u663e\u7136\u8981\u5220\u7684\u6811\u8fb9\u4e0a\u7684\u6743\u503c\u4e00\u5b9a\u8981\u7b49\u4e8e\u975e\u6811\u8fb9\u7684\u6570\u91cf\u3002\u3002<br \/>\u7136\u540e\u5bf9\u6bcf\u4e2a\u4e24\u7aef\u989c\u8272\u4e0d\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u4e4b\u95f4\u7684\u8def\u5f84+1\uff0c\u663e\u7136\u8981\u5220\u6389\u6811\u8fb9\u4e0d\u80fd\u5728\u88ab\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u95f4\u7684\u8def\u5f84\u8de8\u8d8a\u7684\u60c5\u51b5\u4e0b\u518d\u88ab\u8fd9\u4e2a\u4e0d\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u4e4b\u95f4\u7684\u8def\u5f84\u8de8\u8d8a\u3002\u3002<br \/>\u7136\u540e\u7ef4\u62a4\u4e24\u4e2a\u6811\u94fe\u5256\u5206\u3002\u3002\u5206\u522b\u641e\u6811\u8fb9\u548c\u975e\u6811\u8fb9\u3002\u3002\u5c31\u6ca1\u4ec0\u4e48\u95ee\u9898\u4e86\u3002\u3002<br \/>\u5199\u7684\u7d2f\u6b7b\u6655\u3002\u3002\u3002<br \/><strong>\u6211\u53d1\u73b0\u8fd8\u662f\u6211\u5728codeforces\u4e0a\u82f1\u6587\u7684\u8bf4\u660e\u66f4\u6e05\u695a\u4e00\u70b9\u554a\u56e7\u3002\u3002\u3002<br \/>It&#8217;s a interesting problem.If you for every edge,&#160;<br \/>try to remove it and check if it is a&#160;<\/strong>bipartite&#160;<br \/>graph..I think it will get TLE..so let&#8217;s&#160;analysis&#160;<br \/>the property of bipartite graph..<br \/>It should never contain a cycle of odd length&#8230;<br \/>and it can be 2-colored..<br \/>so first build a&#160;spanning forest for the graph..<br \/>and do the 2-color on it(Tree can be 2-colored).<br \/>for&#160;convenience.<br \/>Let TreeEdge={all edge in forest}<br \/>NotTreeEdge={All edge}\/TreeEdge<br \/>ErrorEdge={all edge that two endpoint have the same color..}<br \/>NotErorEdge=NotTreeEdge\/ErroEdge..<br \/>First,consider a edge form NotTreeEdge,remove it&#160;<br \/>can&#8217;t change any node&#8217;s color..so..if |ErrorEdge|=0 of course we can remove all NotTreeEdgeif =1 we just can remove the ErrorEdgeif &gt;1 we can&#8217;t remove any from NotTreeEdge<br \/>Now,Let consider a Edge e from TreeEdge..<br \/>Let Path(Edge e)=the path in forest between e&#8217;s two endpoints..<br \/>if there is a Edge e&#8217; from ErrorEdge that Path(e&#8217;)&#160;<br \/>didn&#8217;t &#160;go through e..it will destroy the bipartite&#160;<br \/>graph..<br \/>if there is a Edge e&#8217; from ErrorEdge that Path(e&#8217;) go through e and there is a Edge e&#8221; from NotErrorEdge that Path(e&#8221;) go through e..it will also destroy the bipartite graph..<br \/>so now we need to know for every edge,how many such path go through it..it require a data structure&#8230;<br \/>one way is to use heavy-light decomposition then we can update every path in O(LogN^2)&#8230;<br \/>another way is to use Link-Cut Tree..It can do the same in O(LogN)&#8230;.<br \/> Code\uff1a<br \/><a href=\"http:\/\/www.ideone.com\/dPS5N\" target=\"_blank\">http:\/\/www.ideone.com\/dPS5N<\/a><a href=\"http:\/\/www.ideone.com\/dPS5N\" target=\"_blank\"><br \/><\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u9053\u597d\u9898\u554a\u3002\u3002\u3002\u60f3\u60f3\u9ebb\u70e6\u3002\u3002\u505a\u505a\u66f4\u9ebb\u70e6\u3002\u3002\u9898\u76ee\u5f88\u7b80\u6d01\uff0c\u7ed9\u4f60\u4e00\u4e2a\u56fe\uff0c\u6c42\u54ea\u4e9b\u8fb9\u5220\u6389\u4e4b\u540e\u80fd\u53d8\u6210\u4e8c\u5206\u56fe\u3002\u3002\u989d\u3002\u3002\u6211WA\u4e86N\u6b21\u3002\u3002\u6bd4\u8d5b\u7684\u65f6\u5019\u80af\u5b9a\u6765\u4e0d\u53ca\u3002\u3002\u3002\u6162\u6162\u5206\u6790\u5427\u3002\u3002\u9996\u5148\u6c42\u751f\u6210\u6811\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u70b92-\u67d3\u8272\uff0c\u90a3\u4e48\u5982\u679c\u5220\u975e\u6811\u8fb9\u7684\u8bdd\uff0c\u663e\u7136\u4efb\u4f55\u70b9\u7684\u989c\u8272\u90fd\u4e0d\u4f1a\u53d8\uff0c\u90a3\u4e48\u5982\u679c\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u67090\u6761\uff0c\u6240\u6709\u975e\u6811\u8fb9\u90fd\u53ef\u4ee5\u5220\uff0c\u67091\u6761\uff0c\u53ea\u6709\u8fd9\u6761\u53ef\u4ee5\u5220\uff0c2\u6761\u6216\u4ee5\u4e0a\uff0c\u90fd\u4e0d\u80fd\u5220\u3002\u3002\u5982\u679c\u5220\u6811\u8fb9\u7684\u8bdd\uff0c\u663e\u7136\u5fc5\u987b\u8981\u641e\u7ffb\u6240\u6709\u7684\u5947\u73af\uff0c\u5206\u6790\u4e00\u4e0b\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4e00\u4e2a\u6811\u4e2d\u4f1a\u51fa\u73b0\u5947\u73af\u3002\u3002\u67d0\u4e2a\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u9020\u6210\u7684\u5947\u73af\u3002\u3002\u4e00\u4e2a\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u548c\u4e00\u4e2a\u4e24\u7aef\u4e0d\u4e00\u6837\u7684\u975e\u6811\u8fb9\u9020\u6210\u7684\u5947\u73af\u3002\u3002\u90a3\u4e48\u628a\u8fd9\u4e2a\u6811\u6811\u94fe\u5256\u5206\u4e00\u4e0b\u3002\u3002\u5bf9\u6bcf\u4e2a\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u4e4b\u95f4\u7684\u8def\u5f84+1\uff0c\u663e\u7136\u8981\u5220\u7684\u6811\u8fb9\u4e0a\u7684\u6743\u503c\u4e00\u5b9a\u8981\u7b49\u4e8e\u975e\u6811\u8fb9\u7684\u6570\u91cf\u3002\u3002\u7136\u540e\u5bf9\u6bcf\u4e2a\u4e24\u7aef\u989c\u8272\u4e0d\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u4e4b\u95f4\u7684\u8def\u5f84+1\uff0c\u663e\u7136\u8981\u5220\u6389\u6811\u8fb9\u4e0d\u80fd\u5728\u88ab\u4e24\u7aef\u989c\u8272\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u95f4\u7684\u8def\u5f84\u8de8\u8d8a\u7684\u60c5\u51b5\u4e0b\u518d\u88ab\u8fd9\u4e2a\u4e0d\u4e00\u6837\u7684\u975e\u6811\u8fb9\u7684\u4e24\u70b9\u4e4b\u95f4\u7684\u8def\u5f84\u8de8\u8d8a\u3002\u3002\u7136\u540e\u7ef4\u62a4\u4e24\u4e2a\u6811\u94fe\u5256\u5206\u3002\u3002\u5206\u522b\u641e\u6811\u8fb9\u548c\u975e\u6811\u8fb9\u3002\u3002\u5c31\u6ca1\u4ec0\u4e48\u95ee\u9898\u4e86\u3002\u3002\u5199\u7684\u7d2f\u6b7b\u6655\u3002\u3002\u3002\u6211\u53d1\u73b0\u8fd8\u662f\u6211\u5728codeforces\u4e0a\u82f1\u6587\u7684\u8bf4\u660e\u66f4\u6e05\u695a\u4e00\u70b9\u554a\u56e7\u3002\u3002\u3002It&#8217;s a interesting problem.If you for every edge,&#160;try to remove it and check if it is a&#160;bipartite&#160;graph..I think it will get TLE..so let&#8217;s&#160;analysis&#160;the property of bipartite graph..It should never contain a cycle of odd length&#8230;and it can be 2-colored..so first build a&#160;spanning forest for the graph..and do the 2-color on it(Tree can be 2-colored).for&#160;convenience.Let TreeEdge={all [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/327"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}