bzoj1638[usaco2007 Mar]cow Traffic Cow traffic
Test instructions
N-point M-side graphs, each with a 0-degree point has unlimited cows, and now they have to go back to the dorm (point 1), the maximum passage through the volume of the road. n≤5000,m≤50000
Exercises
The throughput of a road = the number of scenarios that reach the node to the 0 node * Point 1 to the scenario count of the departure node (I don't know why, this test instructions is completely blurry), and 2 times DFS is on the line.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineDec (i,j,k) for (int i=j;i>=k;i--)6 #defineMAXN 50107 using namespacestd;8 9InlineintRead () {Ten CharCh=getchar ();intf=1, x=0; One while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} A while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); - returnf*x; - } the intf1[maxn],f2[maxn],n,m,f[maxn*Ten],t[maxn*Ten]; - structe{intT,n;}; E es[maxn*Ten];intG[MAXN]; - intDFS1 (intx) { - if(F1[x])returnF1[x]; + if(!g[x]) f1[x]=1;Else{ - for(intI=G[X];I;I=ES[I].N) {f1[x]+=DFS1 (es[i].t);} + } A returnF1[x]; at } - intDFS2 (intx) { - if(F2[x])returnF2[x]; - if(!g[x]) f2[x]=1;Else{ - for(intI=G[X];I;I=ES[I].N) {f2[x]+=DFS2 (es[i].t);} - } in returnF2[x]; - } to intMain () { +N=read (); M=read (); Inc (I,1, m) F[i]=read (), t[i]=read (); -Memset (G,0,sizeof(g)); Inc (I,1, m) es[i]= (e) {f[i],g[t[i]]},g[t[i]]=i; DFS1 (n); theMemset (G,0,sizeof(g)); Inc (I,1, m) es[i]= (e) {t[i],g[f[i]]},g[f[i]]=i; Inc (I,1, N)if(!F2[i]) dfs2 (i); *Inc (I,1, m) f1[0]=max (f1[0],f1[f[i]]*F2[t[i]]); $printf"%d", f1[0]);return 0;Panax Notoginseng}
20160808
bzoj1638[usaco2007 Mar]cow Traffic Cow traffic *