| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
fxxking TLE help me#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define R 222
#define INF 1010101010
int A[R],B[R];
int N,M;
int cap[R][R];
int ck[R];
int flow(int x, int cf, int e) {
if (x == e) return cf;
if (ck[x]) return 0;
ck[x] = true;
for (int y = 0; y <= e ; y++) if (cap[x][y]) {
int f = flow(y, min(cf, cap[x][y]), e);
if (f) {
cap[x][y] -= f;
cap[y][x] += f;
return f;
}
}
return 0;
}
int main()
{
cin >> N >> M;
int S =0,E=N+N+1;
int a,b;
for(int i=1;i<=N;i++){
cin >> a;
cap[i+N][E]=a;
}
for(int i=1;i<=N;i++){
cin >> a;
cap[S][i]=a;
}
for(int i=1;i<=M;i++){
cin >> a >> b;
cap[a][b+N] = INF;
}
int ans = 0;
while(1){
memset(ck,0,sizeof(ck));
int f =flow(S,INF,E);
if(!f) break;
ans += f;
}
int cnt =0;
for(int i=1;i<=N;i++){
if(!ck[i]) cnt++;
if(ck[i+N]) cnt++;
}
cout << ans << endl << cnt << endl;
for(int i=1;i<=N;i++){
if(!ck[i]) cout << i << " -" << endl;
if(ck[i+N]) cout << i << " +" << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator