标签:char poj i++ bsp log color class etc cst
OJ题号:
洛谷2740、POJ1273、HDU1532
思路:
最大流模板。
1 #include<queue> 2 #include<cstdio> 3 #include<cctype> 4 #include<vector> 5 #include<cstring> 6 inline int getint() { 7 char ch; 8 while(!isdigit(ch=getchar())); 9 int x=ch^‘0‘; 10 while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^‘0‘); 11 return x; 12 } 13 const int E=402,V=201,inf=0x7fffffff; 14 int s,t; 15 struct Edge { 16 int from,to,remain; 17 }; 18 Edge e[E]; 19 std::vector<int> g[V]; 20 int sz=0; 21 inline void add_edge(const int u,const int v,const int w) { 22 e[sz]=(Edge){u,v,w}; 23 g[u].push_back(sz); 24 sz++; 25 } 26 int a[V],p[V]; 27 inline int Augment() { 28 memset(a,0,sizeof a); 29 a[s]=inf; 30 std::queue<int> q; 31 q.push(s); 32 while(!q.empty()&&!a[t]) { 33 int x=q.front(); 34 q.pop(); 35 for(unsigned i=0;i<g[x].size();i++) { 36 Edge &y=e[g[x][i]]; 37 if(!a[y.to]&&y.remain) { 38 p[y.to]=g[x][i]; 39 a[y.to]=std::min(a[x],y.remain); 40 q.push(y.to); 41 } 42 } 43 } 44 return a[t]; 45 } 46 inline int EdmondsKarp() { 47 int maxflow=0; 48 while(int flow=Augment()) { 49 for(int i=t;i!=s;i=e[p[i]].from) { 50 e[p[i]].remain-=flow; 51 e[p[i]^1].remain+=flow; 52 } 53 maxflow+=flow; 54 } 55 return maxflow; 56 } 57 int main() { 58 int n=getint(),m=getint(); 59 s=1,t=m; 60 for(int i=0;i<n;i++) { 61 int u=getint(),v=getint(),w=getint(); 62 add_edge(u,v,w); 63 add_edge(v,u,0); 64 } 65 printf("%d\n",EdmondsKarp()); 66 return 0; 67 }
标签:char poj i++ bsp log color class etc cst
原文地址:http://www.cnblogs.com/skylee03/p/7252445.html