题意:

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. 关于MySQL幻读的实验

    该实验基于 CentOS 7 + MySQL 5.7 进行 打开两个窗口连接到MySQL 第一个连接的事务我们命名为  T1 第二个连接的事务我们命名为 T2 T2 发生在 T1 的 O1 操作结束以 ...

  2. [技术翻译]Web网页内容是如何影响电池使用寿命的?

    本周再来翻译一些技术文章,本次预计翻译三篇文章如下: 04.[译]使用Nuxt生成静态网站(Generate Static Websites with Nuxt) 05.[译]Web网页内容是如何影响 ...

  3. CF1200E Compress Words | 字符串hash

    传送门 Examples input 1 5 I want to order pizza output 1 Iwantorderpizza input 2 5 sample please ease i ...

  4. Spring Boot2 系列教程(三十一)Spring Boot 构建 RESTful 风格应用

    RESTful ,到现在相信已经没人不知道这个东西了吧!关于 RESTful 的概念,我这里就不做过多介绍了,传统的 Struts 对 RESTful 支持不够友好 ,但是 SpringMVC 对于 ...

  5. Yolo V3整体思路流程详解!

    结合开源项目tensorflow-yolov3(https://link.zhihu.com/?target=https%3A//github.com/YunYang1994/tensorflow-y ...

  6. python 学习爬虫教程~

    思路:: (本文没有用xpath定位,xpath需要导入第三方库   from lxml import etree) 1.首先通过urllib类获取到网页的所有内容 2.通过partition获取其中 ...

  7. 【智能合约】编写复杂业务场景下的智能合约——可升级的智能合约设计模式(附Demo)

    智能合约的现状 以太坊在区块链上实现了智能合约的概念,用于:同质化通证发行(ERC-20).众筹.投票.存证取证等等,共同点是:合约逻辑简单,只是业务流程中的关键节点,而非整个业务流程.而智能合约想解 ...

  8. python 验证客户端的合法性

    目的:对连接服务器的客户端进行判断 # Server import socket import hmac import os secret_key = bytes('tom', encoding='u ...

  9. BeautifulSoup的简单用法

    官方文档加载比较慢(估计是我党的原因) https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#find-parents ...

  10. 批量解决win10图标上有两个蓝色箭头的方法

    双击“此电脑”,点击“C盘”,可以看到一个”用户“文件夹,双击”用户“, 选择现在正在使用的用户名,双击用户名,找到该文件夹下的”桌面“或”Desktop“点击“属性”, 在“常规”选项卡中的属于项中 ...