# 【 2018南京 】Magic Potion (网络流）

2019/07/23 14:42

There are nnn heroes and mmm monsters living in an island. The monsters became very vicious these days, so the heroes decided to diminish the monsters in the island. However, the iii-th hero can only kill one monster belonging to the set MiM_iMi. Joe, the strategist, has kkk bottles of magic potion, each of which can buff one hero's power and let him be able to kill one more monster. Since the potion is very powerful, a hero can only take at most one bottle of potion.

Please help Joe find out the maximum number of monsters that can be killed by the heroes if he uses the optimal strategy.

#### Input

The first line contains three integers n,m,kn, m, kn,m,k (1≤n,m,k≤5001 \le n, m, k \le 5001n,m,k500) —\text{---}— the number of heroes, the number of monsters and the number of bottles of potion.

Each of the next nnn lines contains one integer tit_iti, the size of MiM_iMi, and the following tit_{i}ti integers Mi,jM_{i, j}Mi,j (1≤j≤ti1 \le j \le t_i1jti), the indices (111-based) of monsters that can be killed by the iii-th hero (1≤ti≤m,1≤Mi,j≤m1 \le t_i\le m, 1\leq M_{i, j} \le m1tim,1Mi,jm).

#### Output

Print the maximum number of monsters that can be killed by the heroes.

#### 样例输入1 复制

3 5 2
4 1 2 3 5
2 2 5
2 1 2

#### 样例输出1 复制

4

#### 样例输入2 复制

5 10 2
2 3 10
5 1 3 4 6 10
5 3 4 6 8 9
3 1 9 10
5 1 3 6 7 10

#### 样例输出2 复制

7SOLUTION:本来的自身流量和额外k个流量是不能混在一起的因为有可能 别的hero的自身流量跑到了别的hero身上CODE:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int inf=1<<28;
int n,m,s,t;
int x=0;
char c=getchar();
while(c>'9'||c<'0')c=getchar();
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return x;
}
struct Node{
int v;
int next;
int val;
}node[300010];
inline void addedge(int u,int v,int val){
node[++cnt].v=v;
node[cnt].val=val;
}
int dep[130000],gap[130000];
void bfs(){
memset(dep,-1,sizeof(dep));
memset(gap,0,sizeof(gap));
dep[t]=0;
gap[0]=1;
queue<int>q;
q.push(t);
while(!q.empty()){
int u=q.front();
q.pop();
int v=node[i].v;
if(dep[v]!=-1)continue;
q.push(v);
dep[v]=dep[u]+1;
gap[dep[v]]++;
}
}
return;
}
int maxflow;
int dfs(int u,int flow){
if(u==t){
maxflow+=flow;
return flow;
}
int used=0;
int d=node[i].v;
if(node[i].val&&dep[d]+1==dep[u]){
int mi=dfs(d,min(node[i].val,flow-used));
if(mi){
node[i].val-=mi;
node[i^1].val+=mi;
used+=mi;
}
if(used==flow)return used;
}
}
--gap[dep[u]];
if(gap[dep[u]]==0)dep[s]=n+1;
dep[u]++;
gap[dep[u]]++;
return used;
}
int ISAP(){
maxflow=0;
bfs();
while(dep[s]<n)dfs(s,inf);
return maxflow;
}
int k;
int main(){

for(int  i=1;i<=n;i++)
{
int p;cin>>p;
for(int j=1;j<=p;j++)
{
// cout<<i<<" "<<2*n+x<<endl;
}
}

for(int i=1;i<=n;i++)

for(int i=1;i<=m;i++)

for(int i=1;i<=m;i++)

for(int i=1;i<=n;i++)

for(int i=1;i<=n;i++)

s=2*n+2*m+1,t=2*n+2*m+3;
n=2*n+2*m+3;

cout<<ISAP();
}
/*
1 1 4
1 1
*/

0
0 收藏

0 评论
0 收藏
0