2018ACM-ICPC亚洲区域赛南京站I题Magic Potion(网络流)
http://codeforces.com/gym/101981/attachments
题意:有n个英雄,m个敌人,k瓶药剂,给出每个英雄可以消灭的敌人的编号。每个英雄只能消灭一个敌人,但每个英雄只能消灭一个敌人。现在有药剂,英雄喝了之后可以多消灭一个敌人,但每个英雄只能喝一瓶,问最多能消灭多少个敌人。
下午在实验室队内自己开训练,和JC大佬那队一起开的,当时JC大佬他们队开的J题,没有看I题,当我们队AC之后JC大佬才看了I题,听到他们说,这题就差直接把网络流三个字写在题目里了。确实非常明显,很明显的一个匹配问题,如果每个英雄只能消灭一个敌人的话就是二分图匹配网络流裸题。刚开始建图错误,建成了这样。

直接把s和s2直接连了一条n+k的边,s2和n个英雄直接建了一条边权为2的边,然后WA了一发。后面发现,有部分英雄如果没有消灭敌人,可能会被当成药剂给别的英雄。

然后找到了正确建图方式,就是这样将药剂和每个英雄的攻击一次分离。在这张图上直接跑最大流就可以了。
最后贴上AC代码

#include<bits/stdc++.h> using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int,int> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define de(x) cout<< #x<<" = "<<x<<endl
#define dd(x) cout<< #x<<" = "<<x<<" "
#define mes(a,b) memset(a,b,sizeof a)
const ll inf= 1e18;
const int N=2005,M=1e6;
int head[N],ver[M],edge[M],Next[M],d[N];
int n,m,s,t,tot,maxflow;
queue<int>q; 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]=0,Next[tot]=head[y],head[y]=tot;
}
bool bfs()
{
mes(d,0);
while(!q.empty()) q.pop();
q.push(s);
d[s]=1;
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]+1;
if(ver[i]==t) return 1;
}
}
}
return 0;
}
int dinic(int x,ll flow)
{
if(x==t) return flow;
int rest=flow,k;
for(int i=head[x];i&&rest;i=Next[i])
{
if(edge[i]&&d[ver[i]]==d[x]+1)
{
k=dinic(ver[i],min(rest,edge[i]));
if(!k) d[ver[i]]=0;
edge[i]-=k;
edge[i^1]+=k;
rest-=k;
}
}
return flow-rest;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
tot=1;
int n,m,k;
cin>>n>>m>>k;
s=0;
t=n+m+1;
int s1=n+m+2,s2=n+m+3;
rept(i,1,n)
{
int cnt;
cin>>cnt;
rept(j,1,cnt)
{
int y;
cin>>y;
add(i,n+y,1);
}
}
add(s,s1,n);
add(s,s2,k);
rept(i,1,n) add(s1,i,1),add(s2,i,1);
rept(i,1,m) add(n+i,t,1);
int flow=0;
while(bfs())
while(flow=dinic(s,inf)) maxflow+=flow;
cout<<maxflow<<"\n";
return 0;
}
2018ACM-ICPC亚洲区域赛南京站I题Magic Potion(网络流)的更多相关文章
- 【2018 ICPC亚洲区域赛南京站 A】Adrien and Austin(博弈)
题意: 有一排n个石子(注意n可以为0),每次可以取1~K个连续的石子,Adrien先手,Austin后手,若谁不能取则谁输. 思路: (1) n为0时的情况进行特判,后手必胜. (2) 当k=1时, ...
- 2013 ACM-ICPC亚洲区域赛南京站C题 题解 轮廓线DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4804 题目大意 给你一个 \(n \times m\) 的矩形区域.你需要用 \(1 \times 1 ...
- 2014ACM/ICPC亚洲区域赛牡丹江站汇总
球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-A ( ZOJ 3819 ) Average Score
Average Score Time Limit: 2 Seconds Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...
- ICPC2019 亚洲区域赛 南京站
蒟蒻终于打完了人生的第一场ICPC了. 终榜去星后rank36,AG,和AU差几十罚时了. 虽有遗憾但总体也是正常发挥了. 不愿再去对比赛做什么回顾,甚至很不愿去想.很多题已经在能力之外,即便是平常熟 ...
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation
Known Notation Time Limit: 2 Seconds Memory Limit: 65536 KB Do you know reverse Polish notation ...
- 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)
Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...
- 【2018 ICPC亚洲区域赛徐州站 A】Rikka with Minimum Spanning Trees(求最小生成树个数与总权值的乘积)
Hello everyone! I am your old friend Rikka. Welcome to Xuzhou. This is the first problem, which is a ...
- 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)
Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...
随机推荐
- Tensorflow object detection API(1)---环境搭建与测试
参考: https://blog.csdn.net/dy_guox/article/details/79081499 https://blog.csdn.net/u010103202/article/ ...
- 关于C#的DataGridView设置了DataSource后Rows无值问题
前言 今天写一个导出到Excel表的东西,以前也写过,之前导出都是将界面上的DataGridView中数据导出,没有任何问题,然而今天的导出场景是在界面是点击导出按钮,直接在数据库中查询符合条件的数据 ...
- git 删除文件 、只删除远程仓库文件、更换远程仓库
一.删除文件 1.克隆远程仓库到本地库. 例如使用ssh方法: git clone git@github.com:xxx/xxx.git 2.对需要删除的文件.文件夹进行如下操作: git rm te ...
- Traverse an expression tree and extract parameters
Traverse an expression tree and extract parameters I think as you've said that using ExpressionVis ...
- graph embedding 使用方法
无论是network embedding 还是graph embedding都是通过节点(node)和边的图,学出每个节点的embedding向量. 比较流行的算法有: Model Paper Not ...
- CMU Database Systems - Indexes
这章主要描述索引,即通过什么样的数据结构可以更加快速的查询到数据 介绍Hash Tables,B+tree,SkipList 以及索引的并行访问 Hash Tables hash tables可以实现 ...
- C# 获取Windows 设备信息
namespace Beisen.Native { using Beisen.Pdf; using System; using System.Runtime.InteropServices; inte ...
- layui 鼠标悬停单元格显示全部
{field : 'subjectId',title : '主题id',align: 'center',edit : 'text',templet:'<div><span title ...
- 免费好用的SSH手机客户端
简单说一些,SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定,SSH 为建立在应用层基础上的安全协议.SSH 是目前较可靠,专 ...
- java8 数据集过滤removeIf和filter
对象如下,需求:只要30岁以下的人 //求职者的实体类 public class Person { private String name;//姓名 private Integer age;//年龄 ...