标签:string wan with cer rom cst eof include miss
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 20892 | Accepted: 9549 |
Description
Input
Output
Sample Input
3 3 3 1 10 2 1 2 2 2 1 3 3 1 2 6
Sample Output
7
Source
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<queue> 5 #include<vector> 6 #define maxn 1050 7 using namespace std; 8 int dep[110],m,n,pig[maxn],house[maxn]; 9 int vis[110],map[110][110]; 10 #define INF 0x7fffffff 11 bool BFS(){ 12 memset(dep,-1,sizeof(dep)); 13 queue<int>q; 14 dep[0]=0;q.push(0); 15 while(!q.empty()){ 16 int u=q.front();q.pop(); 17 for(int v=1;v<=n+1;v++){ 18 if(map[u][v]>0&&dep[v]==-1){ 19 dep[v]=dep[u]+1; 20 if(v==n+1)return 1; 21 else q.push(v); 22 } 23 } 24 } 25 return 0; 26 } 27 int Dinic(){ 28 int maxf=0;vector<int>q; 29 while(BFS()){ 30 memset(vis,0,sizeof(vis)); 31 q.push_back(0);vis[0]=1; 32 while(!q.empty()){ 33 int p=q.back(); 34 if(p==n+1){ 35 int minn,minx=0x7fffffff; 36 for(int i=1;i<q.size();i++){ 37 int u=q[i-1],v=q[i]; 38 if(map[u][v]<minx){ 39 minx=map[u][v]; 40 minn=u; 41 } 42 } 43 maxf+=minx; 44 for(int i=1;i<q.size();i++){ 45 int u=q[i-1],v=q[i]; 46 map[u][v]-=minx;map[v][u]+=minx; 47 } 48 while(!q.empty()&&q.back()!=minn){ 49 vis[q.back()]=0;q.pop_back(); 50 } 51 } 52 else { 53 int i; 54 for(i=0;i<=n+1;i++){ 55 if(map[p][i]>0&&dep[i]==dep[p]+1 56 &&!vis[i]){ 57 q.push_back(i);vis[i]=1; 58 break; 59 } 60 } 61 if(i>n+1)q.pop_back(); 62 } 63 } 64 } 65 return maxf; 66 } 67 int main(){ 68 cin>>m>>n; 69 for(int i=1;i<=m;i++) 70 scanf("%d",pig+i); 71 72 int num,k; 73 for(int i=1;i<=n;i++){ 74 scanf("%d",&num); 75 for(int j=0;j<num;j++){ 76 scanf("%d",&k); 77 if(house[k]==0) map[0][i]+=pig[k]; 78 else map[house[k]][i]=INF; 79 house[k]=i; 80 } 81 int tpig; 82 scanf("%d",&tpig); 83 map[i][n+1]=tpig; 84 } 85 cout<<Dinic()<<endl; 86 return 0; 87 }
标签:string wan with cer rom cst eof include miss
原文地址:http://www.cnblogs.com/suishiguang/p/6485264.html