3931: [CQOI2015] Network throughput time limit: ten Sec Memory Limit: MB
Submit: 853 Solved: 381
[Submit] [Status] [Discuss] Description
Routing refers to the activity of transmitting information from source address to destination site through computer network, which is also the key point and difficulty in computer network design. A hardware device that implements route forwarding in a network is called a router. In order for the packet to reach the destination fastest, the router needs to select the optimal path forward packet. For example, in the Common routing algorithm OSPF (Open Shortest Path first), routers use the classic Dijkstra algorithm to calculate the shortest path, and then try to forward the packets along the shortest path. Now, if you know the connection between routers in a computer network, and the maximum throughput of each router (that is, the number of packets that can be forwarded per second), assume that all packets must be forwarded along the shortest path, and try to calculate the maximum throughput of the network from Router 1 to Router n. The time overhead of forwarding and transmission is ignored in the calculation, regardless of the bandwidth limit of the link, that is to say that the packet can be instantaneous over the network. Router 1 to Router n as the starting point and end point, its own throughput is not considered, the network does not exist to connect 1 and n directly linked links.
Input
The first line of the input file contains two spaces separated by positive integers n and m, each representing the number of routers and the number of links. Routers in the network use 1 to n numbers. Next m lines, each line contains three spaces separated by a positive integer A, B, and D, indicating that there is a two-way link from router A to Router B with a distance of D. Next n rows, each line contains a positive integer c, each of which gives the throughput of each router.
Output
Output an integer for the throughput of the topic.
Sample Input7 10
1 2 2
1 5 2
2 4 1
2 3 3
3 7 1
4 5 4
4 3 1
4 6 1
5 6 2
6 7 1
1
100
20
50
20
60
1
Sample Output -HINT
For 100% of data, n≤500,m≤100000,d,c≤10^9
Source
Shortest Path + maximum flow bare topic
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib > #include <algorithm> #include <queue> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) #define LL Long long#define pa pair<ll,int> #define MAXN 1100#define MAXM 400100#define inf 10000000 00000000llusing namespace Std;int n,m,s,t,cnt=0;int head[maxn],cur[maxn],x[100100],y[100100];ll dis[maxn],c[maxn],z [100100];ll ans=0;bool inq[maxn],vst[maxn];struct edge_type{int to,next;ll v;} E[maxm];inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline void Add_edge (int x,int y,ll z1,ll z2) {e[++cnt]= (Edge_type) {y,head[x],z1};head[x]=cnt;e[++cnt]= (Edge_type) {x, head[y],z2};head[y]=cnt;} inline void Dijkstra () {priority_queue<pa,vector<pa>,greater<pa> > Q;memset (dis,-1,sizeof (dis)); Dis[1]=0;q.Push (Make_pair (0,1)), while (!q.empty ()) {int x=q.top (). Second;q.pop (), while (!q.empty () &&vst[x]) {x=q.top () . Second;q.pop ();} if (Vst[x]) break;vst[x]=true;for (int i=head[x];i;i=e[i].next) {int y=e[i].to;if (dis[y]==-1| | DIS[Y]>DIS[X]+E[I].V) {Dis[y]=dis[x]+e[i].v;q.push (Make_pair (Dis[y],y))}}} inline ll dfs (int x,ll f) {ll tmp,sum=0;if (x==t) return f;for (int &i=cur[x];i;i=e[i].next) {int y=e[i].to;if (E[I].V&A mp;&dis[y]==dis[x]+1) {Tmp=dfs (Y,min (F-SUM,E[I].V)); E[i].v-=tmp;e[i^1].v+=tmp;sum+=tmp;if (sum==f) return sum;}} if (!sum) Dis[x]=-1;return sum;} inline bool BFs () {queue<int> q;memset (dis,-1,sizeof (dis));d Is[s]=0;q.push (s), while (!q.empty ()) {int tmp= Q.front (); Q.pop (); if (tmp==t) return true;for (int i=head[tmp];i;i=e[i].next) if (e[i].v&&dis[e[i].to]==-1) { Dis[e[i].to]=dis[tmp]+1;q.push (e[i].to);}} return false;} inline void Dinic () {while (BFS ()) {F (i,1,t) Cur[i]=head[i];ans+=dfs (S,inf);}} int main () {n=read (); M=read (); F (i,1,m) {x[i]=read (); Y[i]=read (); Z[i]=read ();Add_edge (X[i],y[i],z[i],z[i]);} F (I,1,n) c[i]=read (); C[1]=c[n]=inf;dijkstra (); Memset (Head,0,sizeof (head)); cnt=1;s=1;t=2*n; F (i,1,n) Add_edge (i,i+n,c[i],0); F (i,1,m) {if (Dis[y[i]]==dis[x[i]]+z[i]) Add_edge (x[i]+n,y[i],inf,0), if (Dis[x[i]]==dis[y[i]]+z[i]) Add_edge (y[i]+n , x[i],inf,0);} Dinic ();p rintf ("%lld\n", ans);
bzoj3931 "CQOI2015" Network throughput