题意:

n个英雄,m个怪兽,第i个英雄可以打第i个集合里的怪兽,一个怪兽可以在多个集合里

有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只

n,m,k<=500

思路:

最大流,建图方式:

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
//#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int head[maxn],d[maxn];//层
int ver[maxm],edge[maxm],Next[maxm];//edge[i]: c for edge_i
int n, m, s, t, tot, maxflow;
queue<int>q;
int vis[maxn];//出现过
void add(int x, int y, int z){
ver[++tot]=y,edge[tot]=z,Next[tot]=head[x],head[x]=tot; ver[++tot]=x,edge[tot]=,Next[tot]=head[y],head[y]=tot;
} bool bfs(){
mem(d,);
while(!q.empty())q.pop();
q.push(s);
d[s]=;
while(!q.empty()){
int x = q.front();
q.pop();
for(int i = head[x]; i; i = Next[i]){
if(edge[i] && !d[ver[i]]){
q.push(ver[i]);
d[ver[i]] = d[x] + ;
if(ver[i] == t) return true;
}
}
}
return false;
}
int dinic(int x, int flow){
if(x==t) return flow;
int rest = flow, k;
for(int i = head[x]; i; i = Next[i]){
if(edge[i] && d[ver[i]] == d[x]+){
k = dinic(ver[i], min(rest, edge[i]));
if(!k) d[ver[i]] = ;
edge[i] -= k;
edge[i^] += k;
rest -= k;
}
}
return flow - rest;
} int main(){
int num;
scanf("%d %d %d", &n, &m, &num);
tot = ;
//scanf("%d %d", &s, &t);
s = ;
t = n+m+;
add(s,,num);
for(int i = ; i <= n; i++){
int sz, x;
add(s,+i,);
add(,+i,);
scanf("%d", &sz);
for(int j = ; j <= sz; j++){
scanf("%d", &x);
add(+i,+n+x,);
}
}
for(int i = ; i <= m; i++){
add(+n+i,t,);
}
int flow = ;
maxflow=;
while(bfs()){
while(){
flow = dinic(s,inf);
if(!flow)break;
maxflow+=flow;
}
}
printf("%d\n",maxflow);
return ;
}
/*
3 5 0
4 1 2 3 5
2 2 5
2 1 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 */

2018icpc南京现场赛-I Magic Potion(最大流)的更多相关文章

  1. 2018icpc南京现场赛-G Pyramid(打标找规律+逆元)

    题意: 求n行三角形中等边三角形个数,图二的三角形也算. n<=1e9 思路: 打表找下规律,打表方法:把所有点扔坐标系里n^3爆搜即可 打出来为 1,5,15,35,70,126,210.. ...

  2. 2018ICPC南京网络赛

    2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...

  3. Gym101981D - 2018ACM-ICPC南京现场赛D题 Country Meow

    2018ACM-ICPC南京现场赛D题-Country Meow Problem D. Country Meow Input file: standard input Output file: sta ...

  4. 2018ICPC青岛现场赛 重现训练

    先贴代码,以及简要题解. 和一个队友下午双排打了一下,队友光速签到,我签的J被嫌弃写得慢以及演员...然后我秒出了E了思路然而难以置信这么简单的思路当时才过了十几个,于是发现D.F不是太好做.最后交了 ...

  5. Gym 101981I - Magic Potion - [最大流][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem I]

    题目链接:http://codeforces.com/gym/101981/attachments There are n heroes and m monsters living in an isl ...

  6. Magic Potion(最大流,跑两遍网络流或者加一个中转点)

    Magic Potion http://codeforces.com/gym/101981/attachments/download/7891/20182019-acmicpc-asia-nanjin ...

  7. 2018ACM-ICPC亚洲区域赛南京站I题Magic Potion(网络流)

    http://codeforces.com/gym/101981/attachments 题意:有n个英雄,m个敌人,k瓶药剂,给出每个英雄可以消灭的敌人的编号.每个英雄只能消灭一个敌人,但每个英雄只 ...

  8. HDU - 5136 2014icpc南京现场赛J 计数dp

    题目大意:给你一个树的直径k,要求每个点的度数不超过3, 问你有多少棵树满足条件. 思路:好难啊. 主要思想就是将一棵无根二叉树树划分成有根二叉树. 我们对k的分奇偶讨论: 我们定义dp[ i ] 为 ...

  9. ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...

随机推荐

  1. JavaScript substring()

    JavaScript substring() 方法 参数 描述 start 必需.一个非负的整数,规定要提取的子串的第一个字符在 stringObject 中的位置. stop 可选.一个非负的整数, ...

  2. iOS从gif获取图片数组

    iOS中,当我们UIImageView实现动画时,如果图片是gif则不会自动播放gif图片,我们可以从gif图片中读取出每一帧的图片,然后组成图片数组,之后再实现使用UIImageView实现动画效果 ...

  3. Spring中PropertiesLoaderUtils应用

    FileSystemResource fileSystemResource =new FileSystemResource("D:/home/conf/mail.properties&quo ...

  4. UGUI源码之EventSystem

    今天研究下UGUI的源码,先从EventSystem入手.EventSystem是用来处理点击.键盘输入以及触摸等事件的. 1.BaseInputModule EventSystem开头声明了两个变量 ...

  5. windows创建git并连结github

    1.下载跟自己系统相对应的git版本 2.默认安装 3.绑定用户 git config --global user.name ""git config --global user. ...

  6. 村庄之间建立邮局 - 区间 dp

    There is a straight highway with villages alongside the highway. The highway is represented as an in ...

  7. 发布到远程存储库时遇到错误: Git failed with a fatal error.

    正在推送 master发布到远程存储库时遇到错误: Git failed with a fatal error.Authentication failed for 'http://1212121xxx ...

  8. cf 697C Lorenzo Von Matterhorn 思维

    题目链接:https://codeforces.com/problemset/problem/697/C 两种操作: 1是对树上u,v之间的所有边的权值加上w 2是查询树上u,v之间的边权和 树是满二 ...

  9. Linux初始化Git环境

    第一步:设置Git全局用户名和邮箱 git config --global user.name "你的用户名" git config --global user.email &qu ...

  10. Http协议 Content-Type

    详情:https://www.cnblogs.com/ranyonsue/p/5984001.html *****Referer:包含一个URL,用户从该URL代表的页面出发访问当前请求的页面. ** ...