"BZOJ1266" "AHOI2006" school route shortest circuit map to minimum cut

Source: Internet
Author: User

Exercises

First of all, the bare single source the shortest course.

Then say turn the smallest cut.


Is that we consider that there are many short circuits from the source to the meeting point, we need to cut off some edges so that all the shortest circuits are cut off.

First of all, this is a very bare model, cut off? Minimum Cut!

If you can't imagine it, think of it this way:


We cut all the shortest paths, then each one has a path with several edges, so we need to cut off at least one part of it.

And all local shortest circuits satisfy a property:

is the shortest short-circuit length fixed from the source to a point (obviously, it's "the most" short)

Then we let all the shortest paths are cut off, it will make some in the shortest path one side is cut off, cutting the other side useless,

Then the whole problem into a local, cut off a shortest path, you need to cut off the source and the path of a point (on the shortest road map)


This is obviously a minimal cut.

And the building is to run over the SPFA, and then see which side in a shortest path, add it to the Network diagram.

Then run through the maximum flow (minimum cut) out of the solution.


Determine if the edge is on the shortest path:

U <--(len)--V

DIST[U]+LEN==DIST[V] or dist[v]+len==dist[u].

This can be referred to above "is the shortest path from the source to a point of fixed length (this is obviously, are" the most "short)" the idea.


Code: (A water has been inscribed for such a long time ...) It's longer than the time to knock the code, and I think ... )

#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define N 505#define M 250000#define inf 0x3f3f3f3fusing namespace std;struct yyc{int u,v,len,cost,next;} E[m],road[m>>1];int head[n],cnt;inline void Add (int u,int v,int len) {e[++cnt].v=v;e[cnt].len=len;e[cnt].next= head[u];head[u]=cnt;} int Dist[n];bool in[n];queue<int>q;void SPFA (int s) {while (!q.empty ()) Q.pop (); memset (dist,0x3f,sizeof (Dist)); int I,u,v;q.push (s), Dist[s]=0,in[s]=1;while (!q.empty ()) {U=q.front (), Q.pop (), In[u]=0;for (I=head[u];i;i=e[i].next {v=e[i].v;if (Dist[v]>dist[u]+e[i].len) {dist[v]=dist[u]+e[i].len;if (!in[v]) Q.push (v), In[v]=1;}} return;} int S,t,d[n];bool BFs () {memset (d,0,sizeof (d)), while (!q.empty ()) Q.pop (), int i,u,v;q.push (s);d [S]=1;while (!q.empty ( ) {U=q.front (), Q.pop (); for (I=head[u];i;i=e[i].next) {v=e[i].v;if (!d[v]&&e[i].len) {d[v]=d[u]+1;if (v==t) return 1;q.push (v);}} return 0;} int dinic (int x,int flow) {if (x==t) return flow;int I,V,remain=flow,k;for (I=head[x];i&&remain;i=e[i].next) {if (D[v=e[i].v]==d[x]+1&&e[i].len) {K=dinic (V,min (Remain,e[i].len)); if (!k) d[v]=0;e[i].len-=k,e[i^1].len+=k;remain-=k;}} return flow-remain;} int N,m;int Main () {//freopen ("test.in", "R", stdin), int i,j,k;int a,b,c,d;scanf ("%d%d", &n,&m); for (i=1;i<= m;i++) {scanf ("%d%d%d%d", &road[i].u,&road[i].v,&road[i].len,&road[i].cost); Add (road[i].u,road[i ].v,road[i].len); add (Road[i].v,road[i].u,road[i].len);} SPFA (1); Cnt=1;memset (Head,0,sizeof (head)); for (i=1;i<=m;i++) {if (DIST[ROAD[I].U]+ROAD[I].LEN==DIST[ROAD[I].V] ) Add (Road[i].u,road[i].v,road[i].cost), add (road[i].v,road[i].u,0); if (Dist[road[i].v]+road[i].len==dist[road[i] . u]) Add (road[i].v,road[i].u,road[i].cost), add (road[i].u,road[i].v,0);} S=1,t=n;int Maxflow=0;while (BFS ()) maxflow+=dinic (S,inf);p rintf ("%d\n%d\n", Dist[n],maxflow); return 0;}


"BZOJ1266" "AHOI2006" school route shortest circuit map to minimum cut

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.