题意:有N头牛,F种食物,D种饮料,每头牛有自己喜欢的食物和饮料,每种食物/饮料只能被一头牛享用,每头牛只能享用一种饮料和一种食物,求最后能有几头牛享用到自己的那份套餐(套餐是饮料+食物)。
解法:很容易想到建图方法,食物放左边,饮料放右边,牛放中间,然后按照给定的关系连边,但这里需要对牛拆点,拆点之间流量1.控制牛只选一份套餐;
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<stack>
#include<queue>
#include <iomanip>
#include<iostream>
#include<algorithm>
using namespace std ;
const int N=500 ;
const int M=5000 ;
const int inf=1<<30 ;
struct node
{
int u,v,c,next;
}edge[M];
int pre[N],cur[N],gap[N],dis[N],head[N];
int top ;
int add(int u ,int v,int c)
{
edge[top].u=u;
edge[top].v=v;
edge[top].c=c;
edge[top].next=head[u];
head[u]=top++;
edge[top].u=v;
edge[top].v=u;