{"id":569,"date":"2019-01-15T14:54:33","date_gmt":"2019-01-15T06:54:33","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=569"},"modified":"2019-01-15T14:54:33","modified_gmt":"2019-01-15T06:54:33","slug":"lp3381-%e3%80%90%e6%a8%a1%e6%9d%bf%e3%80%91%e6%9c%80%e5%b0%8f%e8%b4%b9%e7%94%a8%e6%9c%80%e5%a4%a7%e6%b5%81","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2019\/01\/15\/lp3381-%e3%80%90%e6%a8%a1%e6%9d%bf%e3%80%91%e6%9c%80%e5%b0%8f%e8%b4%b9%e7%94%a8%e6%9c%80%e5%a4%a7%e6%b5%81\/","title":{"rendered":"lp3381 \u3010\u6a21\u677f\u3011\u6700\u5c0f\u8d39\u7528\u6700\u5927\u6d41"},"content":{"rendered":"\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u638c\u63e1\u7f51\u7edc\u6d41\u7684\u76f8\u5173\u77e5\u8bc6\u3002 <br>\n\u7136\u540e\uff0c\u6211\u4eec\u4ed4\u7ec6\u89c2\u5bdf\u8d39\u7528\u6d41\u95ee\u9898\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u8fd9\u4e00\u7c7b\u95ee\u9898\u7684\u672c\u8d28\u4e0a\u5c31\u662f\u8ba9\u6211\u4eec\u6c42\u4e00\u4e2a\u5e26\u8def\u5f84\u957f\u5ea6\u7684\u6700\u5927\u6d41\u3002<br>\n\u6545\u800c\uff0c\u6211\u4eec\u8003\u8651\uff0c\u5bf9\u4e8e\u76f8\u540c\u7684\u6d41\u91cf\uff0c\u5c3d\u53ef\u80fd\u5730\u4ece\u8d39\u7528\u5c0f\u7684\u4e00\u6761\u8def\u8d70\u8fc7\u53bb\u2014\u2014\u8fd9\u662f\u4e00\u79cd\u5f88\u663e\u7136\u7684\u8d2a\u5fc3\u3002<br>\n\u5177\u4f53\u7684\u5b9e\u73b0\u4f3c\u4e4e\u4e5f\u5e76\u4e0d\u96be\uff0c\u53ea\u9700\u8981\u5c06\u539f\u6765\u7684\u6734\u7d20\u6c42\u6cd5\uff08EK\uff09\u7a0d\u5fae\u66f4\u6539\u4e00\u4e0b\uff0c\u5c06\u53cd\u8fb9\u7684\u82b1\u8d39\u53d8\u6210\u76f8\u53cd\u6570\uff0c\u7136\u540e\u6c42\u6700\u77ed\u8def\u5373\u53ef\u3002<br>\n\u8003\u8651\u5230\u8d1f\u6743\u8fb9\u7684\u53ef\u80fd\uff0c\u7528SPFA\u4f1a\u6bd4\u8f83\u5feb\u3002\u5f53\u7136\u5982\u679c\u53ea\u6709\u6b63\u6743\u8fb9\u663e\u7136\u662f\u53ef\u4ee5Dijkstra\u7684\u3002 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cstdio>\n#include&lt;queue>\n\nconst int INF = 0x3f3f3f3f;\ninline int Min(int A,int B){\n    return A&lt;B?A:B;\n}\nstruct ee{\n\tint v;\n\tint w;\n\tint c;\n\tint nxt;\n}e[100005];\nint h[5005],et=-1;\ninline void Eadd(int U,int V,int W,int C){\n\te[++et]=(ee){V,W,C,h[U]};\n\th[U]=et;\n}\ninline void add(int U,int V,int W,int C){\n\tEadd(U,V,W,C);Eadd(V,U,0,-C);\n}\nint n,m,s,t,dis[5005],val[5005],fa[5005],nw[5005];\nbool vis[5005];\nstd::queue&lt;int> q;\ninline int spfa(){\n\tfor(int i=1;i&lt;=n;++i){\n\t\tvis[i]=0,dis[i]=INF,val[i]=INF;\n\t}\n\twhile(!q.empty()){\n\t\tq.pop();\n\t}\n\tvis[s]=1,dis[s]=0,fa[t]=-1;\n\tq.push(s);\n\tint p;\n\twhile(!q.empty()){\n\t\tp=q.front();\n\t\tq.pop();\n\t\tvis[p]=0;\n\t\tfor(int i=h[p];i>=0;i=e[i].nxt){\n\t\t\tif(e[i].w>0&amp;&amp;dis[e[i].v]>dis[p]+e[i].c){\n\t\t\t\tdis[e[i].v]=dis[p]+e[i].c;\n\t\t\t\tfa[e[i].v]=p;\n\t\t\t\tnw[e[i].v]=i;\n\t\t\t\tval[e[i].v]=Min(val[p],e[i].w);\n\t\t\t\tif(!vis[e[i].v]){\n\t\t\t\t\tvis[e[i].v]=1;\n\t\t\t\t\tq.push(e[i].v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn fa[t]!=-1;\n}\nvoid init(){\n    scanf(\"%d%d%d%d\",&amp;n,&amp;m,&amp;s,&amp;t);\n    int u,v,w,c;\n    for(int i=1;i&lt;=n;++i){\n        h[i]=-1;\n    }\n    for(int i=1;i&lt;=m;++i){\n        scanf(\"%d%d%d%d\",&amp;u,&amp;v,&amp;w,&amp;c);\n        add(u,v,w,c);\n    }\n    int ansW=0,ansC=0,p;\n    while(spfa()){\n    \tp=t;\n    \tansW+=val[t];\n    \tansC+=val[t]*dis[t];\n    \twhile(p!=s){\n    \t\te[nw[p]].w-=val[t];\n    \t\te[nw[p]^1].w+=val[t];\n    \t\tp=fa[p];\n\t\t} \n    }\n    printf(\"%d %d\\n\",ansW,ansC);\n}\n\nint main(){\n    init();\n    return 0; \n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u638c\u63e1\u7f51\u7edc\u6d41\u7684\u76f8\u5173\u77e5\u8bc6\u3002 \u7136\u540e\uff0c\u6211\u4eec\u4ed4\u7ec6\u89c2\u5bdf\u8d39\u7528\u6d41\u95ee\u9898\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u8fd9\u4e00\u7c7b\u95ee\u9898\u7684\u672c\u8d28\u4e0a\u5c31\u662f\u8ba9\u6211\u4eec\u6c42\u4e00\u4e2a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2019\/01\/15\/lp3381-%e3%80%90%e6%a8%a1%e6%9d%bf%e3%80%91%e6%9c%80%e5%b0%8f%e8%b4%b9%e7%94%a8%e6%9c%80%e5%a4%a7%e6%b5%81\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp3381 \u3010\u6a21\u677f\u3011\u6700\u5c0f\u8d39\u7528\u6700\u5927\u6d41\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,75,80],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/569"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=569"}],"version-history":[{"count":1,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/569\/revisions"}],"predecessor-version":[{"id":570,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/569\/revisions\/570"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=569"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}