{"id":630,"date":"2017-06-16T22:55:20","date_gmt":"2017-06-16T14:55:20","guid":{"rendered":"http:\/\/kylelv.com\/?p=630"},"modified":"2020-03-04T14:56:45","modified_gmt":"2020-03-04T06:56:45","slug":"bzoj-3073-pa2011journeys-%e7%ba%bf%e6%ae%b5%e6%a0%91%e4%bc%98%e5%8c%96%e6%9c%80%e7%9f%ad%e8%b7%af","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=630","title":{"rendered":"bzoj 3073: [Pa2011]Journeys &#8212; \u7ebf\u6bb5\u6811\u4f18\u5316\u6700\u77ed\u8def"},"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-69fdef8866d71\" 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-69fdef8866d71\"  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=630\/#3073_Pa2011Journeys\" title=\"3073: [Pa2011]Journeys\">3073: [Pa2011]Journeys<\/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=630\/#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=630\/#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=630\/#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=630\/#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=630\/#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=630\/#HINT\" title=\"HINT\">HINT<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"3073_Pa2011Journeys\"><\/span>3073: [Pa2011]Journeys<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-text-align-center\">Time Limit:&nbsp;20 Sec&nbsp;&nbsp;Memory Limit:&nbsp;512 MB<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Description\"><\/span>Description<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&nbsp;&nbsp;Seter\u5efa\u9020\u4e86\u4e00\u4e2a\u5f88\u5927\u7684\u661f\u7403\uff0c\u4ed6\u51c6\u5907\u5efa\u9020N\u4e2a\u56fd\u5bb6\u548c\u65e0\u6570\u53cc\u5411\u9053\u8def\u3002N\u4e2a\u56fd\u5bb6\u5f88\u5feb\u5efa\u9020\u597d\u4e86\uff0c\u75281..N\u7f16\u53f7\uff0c\u4f46\u662f\u4ed6\u53d1\u73b0\u9053\u8def\u5b9e\u5728\u592a\u591a\u4e86\uff0c\u4ed6\u8981\u4e00\u6761\u6761\u5efa\u7b80\u76f4\u662f\u4e0d\u53ef\u80fd\u7684\uff01\u4e8e\u662f\u4ed6\u4ee5\u5982\u4e0b\u65b9\u5f0f\u5efa\u9020\u9053\u8def\uff1a(a,b),(c,d)\u8868\u793a\uff0c\u5bf9\u4e8e\u4efb\u610f\u4e24\u4e2a\u56fd\u5bb6x,y\uff0c\u5982\u679ca&lt;=x&lt;=b,c&lt;=y&lt;=d\uff0c\u90a3\u4e48\u5728xy\u4e4b\u95f4\u5efa\u9020\u4e00\u6761\u9053\u8def\u3002Seter\u4fdd\u8bc1\u4e00\u6761\u9053\u8def\u4e0d\u4f1a\u4fee\u5efa\u4e24\u6b21\uff0c\u4e5f\u4fdd\u8bc1\u4e0d\u4f1a\u6709\u4e00\u4e2a\u56fd\u5bb6\u4e0e\u81ea\u5df1\u4e4b\u95f4\u6709\u9053\u8def\u3002Seter\u597d\u4e0d\u5bb9\u6613\u5efa\u597d\u4e86\u6240\u6709\u9053\u8def\uff0c\u4ed6\u73b0\u5728\u5728\u4f4d\u4e8eP\u53f7\u7684\u9996\u90fd\u3002Seter\u60f3\u77e5\u9053P\u53f7\u56fd\u5bb6\u5230\u4efb\u610f\u4e00\u4e2a\u56fd\u5bb6\u6700\u5c11\u9700\u8981\u7ecf\u8fc7\u51e0\u6761\u9053\u8def\u3002\u5f53\u7136\uff0cSeter\u4fdd\u8bc1P\u53f7\u56fd\u5bb6\u80fd\u5230\u4efb\u610f\u4e00\u4e2a\u56fd\u5bb6\u3002&nbsp;&nbsp;&nbsp;\u6ce8\u610f\uff1a\u53ef\u80fd\u6709\u91cd\u8fb9<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Input\"><\/span>Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&nbsp;\u7b2c\u4e00\u884c\u4e09\u4e2a\u6570N,M,P\u3002N&lt;=500000,M&lt;=100000\u3002\u540eM\u884c\uff0c\u6bcf\u884c4\u4e2a\u6570A\uff0cB\uff0cC\uff0cD\u30021&lt;=A&lt;=B&lt;=N,1&lt;=C&lt;=D&lt;=N\u3002&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&nbsp;N\u884c\uff0c\u7b2ci\u884c\u8868\u793aP\u53f7\u56fd\u5bb6\u5230\u7b2ci\u4e2a\u56fd\u5bb6\u6700\u5c11\u9700\u8981\u7ecf\u8fc7\u51e0\u6761\u8def\u3002\u663e\u7136\u7b2cP\u884c\u5e94\u8be5\u662f0\u3002&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Input\"><\/span>Sample Input<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>5 3 4<br>1 2 4 5<br>5 5 4 4<br>1 1 3 3<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sample_Output\"><\/span>Sample Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>1<br>1<br>2<br>0<br>1<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"HINT\"><\/span>HINT<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6211\u4eec\u53d1\u73b0\u672c\u9898\u70b9\u6570\u975e\u5e38\u591a\uff0c\u9700\u8981\u5efa\u7684\u8fb9\u4e5f\u975e\u5e38\u591a\uff0c\u5982\u679c\u76f4\u63a5\u5efa\u56fe\u7684\u8bdd\u4e00\u5b9a\u4f1aTLE+MLE<\/p>\n\n\n\n<p>\u4f46\u662f\u6211\u4eec\u4f1a\u53d1\u73b0\u672c\u9898\u6709\u4e00\u4e2a\u5f88\u597d\u7684\u6027\u8d28\uff0c\u5c31\u662f\u8fde\u7eed\u4e00\u6bb5\u533a\u95f4\u90fd\u53ef\u4ee5\u5230\u8fbe\u53e6\u5916\u8fde\u7eed\u4e00\u6bb5\u533a\u95f4<\/p>\n\n\n\n<p>\u5982\u4f55\u4f18\u5316\u8fd9\u6837\u8fde\u7eed\u7684\u533a\u95f4\uff0c\u6211\u4eec\u5c31\u4f1a\u60f3\u5230\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u2014\u2014\u7ebf\u6bb5\u6811<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u7ebf\u6bb5\u6811\u4e00\u6bb5\u533a\u95f4\u6620\u5c04\u5230\u8fd9\u91cc\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u7528\u7ebf\u6bb5\u6811\u4e0a\u7684\u51e0\u6bb5\u5b8c\u6574\u8868\u793a\u6574\u4e2a\u533a\u95f4\uff0c\u8fd9\u4e5f\u53ef\u4ee5\u770b\u6210\u5c06\u70b9\u6253\u5305\u7684\u601d\u60f3<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u8003\u8651\u5982\u4f55\u4ece\u3010a,b\u3011\u5230\u3010c,d\u3011\u8fde\u8fb9<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u5982\u679c\u6211\u4eec\u8fd8\u662f\u76f4\u63a5\u5c06\u6bcf\u6bb5\u7ebf\u6bb5\u8fde\u8fb9\u7684\u8bdd\u5b83\u7684\u590d\u6742\u5ea6\u8fd8\u662f\u5f88\u9ad8<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u8003\u8651\u62bd\u8c61\u6210\u65b0\u5efa\u4e24\u4e2a\u70b9P1,P2\uff0c\u8868\u793a\u4e24\u6bb5\u533a\u95f4\uff0c\u8fd9\u6837\u4ece\u3010a,b\u3011\u5230\u3010c,d\u3011\uff0c\u5c31\u662f\u76f8\u5f53\u4e8e\u4eceP1\u5230P2\u8fde\u4e00\u6761\u8fb9<\/p>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u53ea\u8981\u6240\u6709\u7ebf\u6bb5\u3010a,b\u3011\u5411P1\u8fde\u8fb9\uff0cP2\u5411\u6240\u6709\u7ebf\u6bb5\u3010c,d\u3011\u8fde\u8fb9\u5c31\u53ef\u4ee5\u505a\u5230\u4e86<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u8fd9\u91cc\u8fd8\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5982\u679c\u628a\u56fe\u5efa\u5230\u4e00\u68f5\u7ebf\u6bb5\u6811\u4e2d\u5c31\u4f1a\u51fa\u73b0\u7ebf\u6bb5\u91cd\u53e0\uff0c\u5c31\u4f1a\u51fa\u95ee\u9898<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5efa\u4e24\u68f5\u7ebf\u6bb5\u6811A\uff0cB\uff0c\u8868\u793a\u4eceA\u4f1a\u7ecf\u8fc7\u4e00\u6761P\u8fb9\u5230B\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u8868\u793a\u7ecf\u8fc7\u4e86\u4e00\u6761\u8fb9<\/p>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u5bf9\u4e8eA\u7ebf\u6bb5\u6811\u4e2d\u7684\u70b9\u4ece\u513f\u5b50\u5411\u7236\u4eb2\u8fde\u4e00\u6761\u6743\u503c\u4e3a0\u7684\u8fb9\uff08\u56e0\u4e3a\u5b83\u672c\u8eab\u5c5e\u4e8e\u8fd9\u4e2a\u96c6\u5408\uff0c\u4e0d\u9700\u8981\u4ee3\u4ef7\uff09<\/p>\n\n\n\n<p>\u4eceB\u7ebf\u6bb5\u6811\u4e2d\u7684\u7239\u5411\u513f\u5b50\u8fde\u4e00\u6761\u6743\u503c\u4e3a0\u7684\u8fb9\uff08\u56e0\u4e3a\u80fd\u5230\u7239\u4e00\u5b9a\u4e5f\u80fd\u5230\u513f\u5b50\uff0c\u4e0d\u9700\u8981\u4ee3\u4ef7\uff09<\/p>\n\n\n\n<p>\u518d\u4eceB\u4e2d\u7684\u53f6\u5b50\u8282\u70b9\u5411A\u4e2d\u5bf9\u5e94\u53f6\u5b50\u8282\u70b9\u8fde\u4e00\u6761\u6743\u503c\u4e3a0\u7684\u8fb9\uff08\u8d70\u5b8c\u4e00\u6761\u8def\u5f84\uff0c\u5230\u8fbe\u5bf9\u5e94\u70b9\uff0c\u7ee7\u7eed\u4ece\u5b83\u5f00\u59cb\u51fa\u53d1\uff09<\/p>\n\n\n\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u8dd1\u6700\u77ed\u8def\u4e86<\/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 inf 1000000007\n#define ll long long\n#define M 4000010\n#define N 500010\ninline int rd()\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 n,m,p;\nint lj&#91;M],to&#91;M&lt;&lt;3],v&#91;M&lt;&lt;3],fro&#91;M&lt;&lt;3],cnt,ls&#91;N&lt;&lt;3],rs&#91;N&lt;&lt;3],ra,rb,tot,val&#91;N],dis&#91;M];\ninline int add(int a,int b,int c){fro&#91;++cnt]=lj&#91;a];to&#91;cnt]=b;v&#91;cnt]=c;lj&#91;a]=cnt;}\nvoid build(int l,int r,int &amp;x,int op)\n{\n    x=++tot;\n    if(l==r){if(op) val&#91;l]=x;return;}\n    int mid=l+r>>1;\n    build(l,mid,ls&#91;x],op);build(mid+1,r,rs&#91;x],op);\n    if(op) add(ls&#91;x],x,0),add(rs&#91;x],x,0);\n    else add(x,ls&#91;x],0),add(x,rs&#91;x],0);\n}\nvoid fadd(int l,int r,int x,int y)\n{\n    if(l==r){add(y,x,0);return;}\n    int mid=l+r>>1;\n    fadd(l,mid,ls&#91;x],ls&#91;y]);fadd(mid+1,r,rs&#91;x],rs&#91;y]);\n}\nvoid padd(int l,int r,int p,int L,int R,int x,int op)\n{\n    if(L==l&amp;&amp;R==r)\n    {\n        if(op) add(x,p,0);\n        else add(p,x,0);\n        return;\n    }\n    int mid=l+r>>1;\n    if(L>mid) padd(mid+1,r,p,L,R,rs&#91;x],op);\n    else if(R&lt;=mid) padd(l,mid,p,L,R,ls&#91;x],op);\n    else \n    {\n        padd(l,mid,p,L,mid,ls&#91;x],op);\n        padd(mid+1,r,p,mid+1,R,rs&#91;x],op);\n    }\n}\nvoid link(int a,int b,int c,int d)\n{\n    padd(1,n,++tot,a,b,ra,1);add(tot,tot+1,1);\n    padd(1,n,++tot,c,d,rb,0);\n}\n#define pa pair&lt;int,int>\npriority_queue&lt;pa,vector&lt;pa >,greater&lt;pa > >q;\nbool vs&#91;M];\nvoid dij()\n{\n    memset(dis,0x3f,sizeof(dis));\n    int l=0,r=1,x;\n    dis&#91;val&#91;p]]=0;\n    q.push(make_pair(0,val&#91;p]));\n    while(!q.empty())\n    {\n        x=q.top().second;q.pop();\n        if(vs&#91;x]) continue;vs&#91;x]=1;\n        for(int i=lj&#91;x];i;i=fro&#91;i])\n            if(dis&#91;to&#91;i]]>dis&#91;x]+v&#91;i])\n            {\n                dis&#91;to&#91;i]]=dis&#91;x]+v&#91;i];\n                q.push(make_pair(dis&#91;to&#91;i]],to&#91;i]));\n            }\n    }\n}\nint main()\n{\n    int a,b,c,d;\n    n=rd();m=rd();p=rd();\n    build(1,n,ra,1);build(1,n,rb,0);fadd(1,n,ra,rb);\n    for(int i=1;i&lt;=m;i++)\n    {\n        a=rd();b=rd();c=rd();d=rd();\n        link(a,b,c,d);link(c,d,a,b);\n    }\n    dij();\n    for(int i=1;i&lt;=n;i++) printf(\"%d\\n\",dis&#91;val&#91;i]]);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>3073: [Pa2011]Journeys Time Limit:&nbsp;20 Sec&nbsp;&#038;nb [&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":[22,10],"class_list":["post-630","post","type-post","status-publish","format-standard","hentry","category-bzoj","tag-22","tag-10"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/630","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=630"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/630\/revisions\/631"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}