标签:style blog http color java os io for
3 3 3 1 10 2 1 2 2 2 1 3 3 1 2 6
7
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #include <queue> 10 #define LL long long 11 #define INF 0x3f3f3f3f 12 using namespace std; 13 const int maxn = 1005; 14 int n,m,a[maxn],p[maxn]; 15 int arc[maxn][maxn],pre[maxn],pigs[maxn]; 16 int bfs(){ 17 int u,v,f = 0; 18 queue<int>q; 19 while(true){ 20 while(!q.empty()) q.pop(); 21 memset(a,0,sizeof(a)); 22 memset(p,0,sizeof(p)); 23 a[0] = INF; 24 q.push(0); 25 while(!q.empty()){ 26 u = q.front(); 27 q.pop(); 28 for(v = 0; v <= n+1; v++){ 29 if(!a[v] && arc[u][v] > 0){ 30 a[v] = min(a[u],arc[u][v]); 31 p[v] = u; 32 q.push(v); 33 } 34 } 35 if(a[n+1]) break; 36 } 37 if(!a[n+1]) break; 38 for(u = n+1; u; u = p[u]){ 39 arc[p[u]][u] -= a[n+1]; 40 arc[u][p[u]] += a[n+1]; 41 } 42 f += a[n+1]; 43 } 44 return f; 45 } 46 int main(){ 47 int i,j,k,buy,e; 48 while(~scanf("%d%d",&m,&n)){ 49 memset(arc,0,sizeof(arc)); 50 memset(pre,0,sizeof(pre)); 51 for(i = 1; i <= m; i++) 52 scanf("%d",pigs+i); 53 for(i = 1; i <= n; i++){ 54 scanf("%d",&k); 55 while(k--){ 56 scanf("%d",&e); 57 if(pre[e]) arc[pre[e]][i] = INF; 58 else arc[pre[e]][i] += pigs[e]; 59 pre[e] = i; 60 } 61 scanf("%d",&buy); 62 arc[i][n+1] += buy; 63 } 64 cout<<bfs()<<endl; 65 } 66 return 0; 67 }
BNUOJ 1268 PIGS,布布扣,bubuko.com
标签:style blog http color java os io for
原文地址:http://www.cnblogs.com/crackpotisback/p/3897985.html