# UVA-10779 Collectors Problem （网络流建模）

# include<iostream>
# include<cstdio>
# include<cmath>
# include<string>
# include<vector>
# include<list>
# include<set>
# include<map>
# include<queue>
# include<cstring>
# include<algorithm>
using namespace std;

# define LL long long
# define REP(i,s,n) for(int i=s;i<n;++i)
# define CL(a,b) memset(a,b,sizeof(a))
# define CLL(a,b,n) fill(a,a+n,b)

const double inf=1e30;
const int INF=1<<30;
const int N=80;

struct Edge
{
int fr,to,cap,fw;
Edge(int _fr,int _to,int _cap,int _fw):fr(_fr),to(_to),cap(_cap),fw(_fw){}
};
vector<Edge>edges;
vector<int>G[N];
int vis[N],d[N],cur[N],s,t,n,m,mark[30];

void init()
{
s=0,t=n+m+1;
edges.clear();
REP(i,0,t+1) G[i].clear();
}

{
edges.push_back(Edge(u,v,cap,0));
edges.push_back(Edge(v,u,0,0));
int len=edges.size();
G[u].push_back(len-2);
G[v].push_back(len-1);
}

bool BFS()
{
queue<int>q;
CL(vis,0);
d[s]=0;
vis[s]=1;
q.push(s);
while(!q.empty())
{
int x=q.front();
q.pop();
REP(i,0,G[x].size()){
Edge &e=edges[G[x][i]];
if(!vis[e.to]&&e.cap>e.fw){
vis[e.to]=1;
d[e.to]=d[x]+1;
q.push(e.to);
}
}
}
return vis[t];
}

int DFS(int x,int a)
{
if(x==t||a==0) return a;
int flow=0,f;
for(int &i=cur[x];i<G[x].size();++i){
Edge &e=edges[G[x][i]];
if(d[e.to]==d[x]+1&&(f=DFS(e.to,min(a,e.cap-e.fw)))>0){
e.fw+=f;
edges[G[x][i]^1].fw-=f;
flow+=f;
a-=f;
if(a==0) break;
}
}
return flow;
}

int Dinic()
{
int flow=0;
while(BFS()){
CL(cur,0);
flow+=DFS(s,INF);
}
return flow;
}

int main()
{
int T,k,r,cas=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
CL(mark,0);
scanf("%d",&k);
while(k--)
{
scanf("%d",&r);
++mark[r];
}
REP(i,1,n){
CL(mark,0);
scanf("%d",&k);
while(k--){
scanf("%d",&r);
++mark[r];
}
REP(j,1,m+1){
}
}
printf("Case #%d: %d\n",++cas,Dinic());
}
return 0;
}


• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
09-18 1202
03-16 3102
08-20 6424
03-13 3430
09-17 6422
03-28 3508

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。