Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

【EK】

Posted by 843040610 at 2017-03-31 15:55:48 on Problem 1149
EK:
#include<stdio.h>
#include<algorithm>
#include<queue>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 99999999
using namespace std;const int N=203;
int n,m,flow,S[N][N],pig[N*10],que[N], pre[N];
bool bfs(){                             
____queue<int>q;bool vis[N]={0};vis[0]=true;q.push(0);
____while(!q.empty()){int u =q.front();q.pop();
____go(v,0,n)if(!vis[v]&&S[u][v]){vis[v]=1;pre[v]=u;
____if(v==n)return 1;q.push(v);}}return 0;
}
int aug(){int u,a=inf;
____u=n;while(u)a=min(a,S[pre[u]][u]),u=pre[u];
____u=n;while(u)S[pre[u]][u]-=a,S[u][pre[u]]+=a,u=pre[u];return a;
}
int main(){
____int k,cnt;scanf("%d%d",&m,&n);
____go(i,1,m)scanf("%d",&pig[i]);go(i,1,n){scanf("%d",&cnt);
____go(p,1,cnt){scanf("%d",&k);if(!pre[k])S[0][i]+=pig[k];
____else S[pre[k]][i]=inf;pre[k]=i;}scanf("%d",&S[i][n+1]);}n++;
____while(bfs())flow+=aug();printf("%d\n",flow);return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator