# POJ-3281 Dining（最大流)

63人阅读 评论(0)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#define maxn 605
#define INF 1e9
typedef long long ll;

using namespace std;
struct Edge{
Edge(){
}
Edge(int a, int b, int c, int d){
from = a;
to = b;
cap = c;
flow = d;
}
int from, to, cap, flow;
};
vector<Edge> edge;
vector<int> v[maxn];
int p[maxn], a[maxn], n, f, d;

edge.push_back(Edge(from, to, 1, 0));
edge.push_back(Edge(to, from, 0, 0));
int dd = edge.size();
v[from].push_back(dd-2);
v[to].push_back(dd-1);
}
void Init(){

edge.clear();
for(int i = 0; i < maxn; i++)
v[i].clear();
for(int i = 1; i <= n; i++){
int k1, k2, a;
scanf("%d%d", &k1, &k2);
for(int j = 1; j <= k1; j++){
scanf("%d", &a);
}
for(int j = 1; j <= k2; j++){
scanf("%d", &a);
}
}
for(int i = 1; i <= f; i++){
}
for(int i = 1; i <= d; i++){
}
for(int i = 1; i <= n; i++){
}
}
int MaxFlow(){

int e = f + 2 * n + d + 1;
int ans = 0;
while(1){

memset(a, 0, sizeof(a));
a[0] = INF;
queue<int> q;
q.push(0);
while(!q.empty()){

int k = q.front();
q.pop();
for(int i = 0; i < v[k].size(); i++){
Edge &e = edge[v[k][i]];
if(a[e.to] == 0 && e.cap > e.flow){
a[e.to] = min(a[k], e.cap - e.flow);
q.push(e.to);
p[e.to] = v[k][i];
}
}
}
if(a[e] == 0)
break;
ans += a[e];
for(int i = e; i != 0; i = edge[p[i]].from){
edge[p[i]].flow += 1;
edge[p[i]^1].flow -= 1;
}
}
return ans;
}
int main(){

//  freopen("in.txt", "r", stdin);
while(scanf("%d%d%d",&n, &f, &d) == 3){
Init();
cout << MaxFlow() << endl;
}
return 0;
}
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：51285次
• 积分：4775
• 等级：
• 排名：第6040名
• 原创：442篇
• 转载：36篇
• 译文：0篇
• 评论：8条
最新评论