Wikioi 1034 Real-time dynamic network traffic (expense flow)

Source: Internet
Author: User

Because with the passage of time. Network side becomes, therefore, the common network traffic can not solve this problem. If T after all transit time.

For this We can split points based on time, and all points will be divided into T points.

For each point, the next time even a capacity for my INF edge, cost 1 edge. This means that the current space station waits 1.

Each point can be reached at the next moment. With one edge, capacity is the capacity of this spaceship, the cost is 1.

The source point is 0 times the Earth, the capacity is K, all the moon connects the meeting point. The cost is 0.

Each time a shortest path is found to augment. If the augmented traffic reaches the total number, exit.

At this time to find the last moment to reach the moon, is finally the moment .

The look of the building map.



#include <cstdio> #include <queue> #include <algorithm> #include <cstring>using namespace std;# Define MAXN 10000#define maxm 1000000#define INF 0x3f3f3f3fstruct node{int u,v,f,c,next;} E[maxm];int N,head[maxn],pre[maxn],dist[maxn],vis[maxn],ans;int En,s,t,maxflow,mincost; s source point. T meeting point void Add (int u,int v,int c,int f)//plus Edge {e[en].u=u;e[en].v=v;e[en].c=c;e[en].f=f;e[en].next=head[u];head[u]=en++;e[ en].u=v;e[en].v=u;e[en].c=-c;e[en].f=0;e[en].next=head[v];head[v]=en++;} int SPFA () {int i,u,v;for (i=0;i<=t;i++) pre[i]=-1,vis[i]=0,dist[i]=inf;dist[s]=0;vis[s]=1;queue<int>q; Q.push (s), while (!q.empty ()) {U=q.front (); Q.pop (), for (I=head[u];i!=-1;i=e[i].next) {v=e[i].v;if (e[i].f>0& &AMP;DIST[U]+E[I].C&LT;DIST[V] {dist[v]=dist[u]+e[i].c;pre[v]=i;if (!vis[v]) {Vis[v]=1;q.push (v);}}} vis[u]=0;} if (Dist[t]==inf) return 0;return 1;} void Add () {int v;int maxf=inf;for (v=pre[t];~v;v=pre[e[v].u]) maxf=min (MAXF,E[V].F); for (v=pre[t];~v;v=pre[e[v].u]) { E[V].F-=MAXF;E[V^1].F+=MAXF;} Ans=max (ans,e[pRE[T]].U);//Save the last time you reach the moon, the larger the back subscript. MAXFLOW+=MAXF;}    void Init () {maxflow=0;    mincost=0;    en=0; memset (head,-1,sizeof (Head));} int Num[55][55],have[55],r[55];int Main () {int i,j,a,b,c,m,k;while (scanf ("%d%d%d", &n,&m,&k)!=EOF) {ans=    0;    Init ();            for (int i=1;i<=m;i++) {scanf ("%d%d", &r[i],&have[i]);                for (int j=0;j

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Wikioi 1034 Real-time dynamic network traffic (expense flow)

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.