标签:void cpp int com set dep == += problem
就是个模板
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
int point;
int nxt;
int value;
};
node line[500000];
int head[5000],tail=-1;
void add(int x,int y,int z)
{
line[++tail].point=y;
line[tail].value=z;
line[tail].nxt=head[x];
head[x]=tail;
line[++tail].point=x;
line[tail].value=0;
line[tail].nxt=head[y];
head[y]=tail;
}
int dep[50000],cur[50000];
bool BFS(int begin,int end)
{
for(int i=begin;i<=end;i++)
{
dep[i]=0;
cur[i]=head[i];
}
queue<int>q;
q.push(begin);
dep[begin]=1;
while(!q.empty())
{
int pas=q.front();
q.pop();
for(int i=head[pas];i!=-1;i=line[i].nxt)
if(!dep[line[i].point]&&line[i].value)
{
dep[line[i].point]=dep[pas]+1;
q.push(line[i].point);
}
}
if(dep[end])
return true;
return false;
}
int dfs(int now,int aim,int limte)
{
if(now==aim||!limte)
return limte;
int flow=0,f;
for(int i=cur[now];i!=-1;i=line[i].nxt)
{
cur[now]=i;
if(dep[line[i].point]==dep[now]+1&&(f=dfs(line[i].point,aim,min(limte,line[i].value))))
{
flow+=f;
limte-=f;
line[i].value-=f;
line[i^1].value+=f;
if(!limte)
break;
}
}
return flow;
}
int dinic(int begin,int end)
{
int res=0;
while(BFS(begin,end))
res+=dfs(begin,end,0x7fffffff);
return res;
}
int k[10000];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<=n+m+1;i++)
head[i]=-1;
tail=-1;
for(int i=1;i<=m;i++)
scanf("%d",&k[i]);
int num,data,pas;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&num,&data);
add(0,i,num);
for(int j=1;j<=data;j++)
{
scanf("%d",&pas);
add(i,n+pas,1);
}
}
for(int i=1;i<=m;i++)
add(n+i,n+m+1,k[i]);
dinic(0,n+m+1);
bool fail=true;
for(int i=head[n+m+1];i!=-1;i=line[i].nxt)
if(line[i^1].value)
{
printf("No\n");
fail=false;
break;
}
if(fail)
printf("Yes\n");
}
}
标签:void cpp int com set dep == += problem
原文地址:https://www.cnblogs.com/Lance1ot/p/9021903.html