【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)
题目链接:
http://codeforces.com/gym/100825
题目大意:
N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<=200)个工厂在F个点上,不会有一个点既有生产商又有工厂
有T(T<=1000)个公司,每个公司能够到达Ci个点,并且一个只能运输一个生产商的货物。比如生产商1给工厂1运输货物需要用到公司1,那么其余生产商就不能用公司1
一个工厂需要任意一个生产商供应货物,求最多能够给多少个工厂供应货物。
题目思路:
【最大流】
因为一个公司只能被一个生产商使用,所以将每个公司拆点为A入和A出两个点,A入到A出中间流量为1
A公司能够到达的所有点向A入连一条流量为1的边,A出到所能能到达的点连一条流量为1的边。
设置超级源S和超级汇T,超级源S到每一个生产商连一条流量为1的边,每个工厂到超级汇T连一条流量为1的边。
跑一遍最大流即可。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 3004
#define M 5000004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int S,T,nn,m1,m2;
int d[N],vd[N],last[N];
struct xxx
{
int next,to,q;
}a[M];
int ma[N][N];
string ss;
string s[N];
map<string,int>id;
void add(int x,int y,int z)
{
a[++lll].to=y;
a[lll].q=z;
a[lll].next=last[x];
last[x]=lll;
}
int sap(int u,int f)
{
int i,v,tt,asp=,mix=nn-;
if(u==T)return f;
for(i=last[u];i!=;i=a[i].next)
{
v=a[i].to;
if(a[i].q>)
{
if(d[u]==d[v]+)
{
tt=sap(v,min(f-asp,a[i].q));
asp+=tt;
a[i].q-=tt;
a[i^].q+=tt;
if(asp==f || d[S]==nn)
return asp;
}
mix=min(mix,d[v]);
}
}
if(asp!=)return asp;
if(!--vd[d[u]])d[S]=nn;
else vd[d[u]=mix+]++;
return asp;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z,f;
// init();
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
lll=;
scanf("%d%d%d",&m1,&m2,&m);
S=n+m+m+,T=n+m+m+;
for(i=;i<=m1;i++)
{
cin>>ss;
if(id.find(ss)==id.end())
id[ss]=++cass;
j=id[ss];
add(S,j,);
add(j,S,);
}
for(i=;i<=m2;i++)
{
cin>>ss;
if(id.find(ss)==id.end())
id[ss]=++cass;
j=id[ss];
add(j,T,);
add(T,j,);
}
for(i=;i<=m;i++)
{
add(n+i+i-,n+i+i,),add(n+i+i,n+i+i-,);
scanf("%d",&cas);
for(j=;j<=cas;j++)
{
cin>>s[j];
if(id.find(s[j])==id.end())
id[s[j]]=++cass;
k=id[s[j]];
add(k,n+i+i-,),add(n+i+i-,k,);
add(n+i+i,k,),add(k,n+i+i,);
}
}
nn=T;
vd[]=nn;
while(d[S]<nn)
{
f=sap(S,MAX);
ans+=f;
}
printf("%d\n",ans); cass=;ans=;
mem(last,);mem(d,);mem(vd,);
id.clear();
}
return ;
}
/*
// //
*/
【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)的更多相关文章
- 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N个点M条无向边,(N<=100,M<=N(N-1)/2),起始感染源S,时间T(T<10) ...
- 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空 ...
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...
- codeforces gym 100825 D Rings
这题果然就是个暴力题.... 看每个T的四个方向,有'.',或者在边界上就填1 不然就填四个方向上最小的那个数再加1 然而写wa了几发,有点蠢... #include <bits/stdc++. ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- F - Qualification Rounds CodeForces - 868C 二进制
F - Qualification Rounds CodeForces - 868C 这个题目不会,上网查了一下,发现一个结论就是如果是可以的,那么两个肯定可以满足. 然后就用二进制来压一下这个状态就 ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
随机推荐
- 配置Nginx 1.8支持PHP 5.6
启动PHP和Nginx 修改Nginx配置文件/usr/local/nginx/conf/nginx.conf server { listen ; server_name localhost; loc ...
- windows下jboss启动、配置、访问
window 下的jboss启动.配置.访问 1.进入jboss\server\default\deploy\jboss-web.deployer 执行run命令 2.jboss访问地址:http:/ ...
- <thead>
<thead> 标签定义表格表头该标签用于组合 HTML 表格表头内容 thead 元素应该与 tbody 和 tfoot 元素结合起来使用 tbody 元素用于对 HTML 表格主体内容 ...
- hadoop2集群中的datanode启动以后自动关闭的问题
今天在启动前几天搭建成功的hadoop集群的时候,出现了datanode启动之后自动关闭的情况,经过查询之后发现问题产生的原因是:在第一次格式化dfs后,启动并使用了hadoop,后来又重新执行了格式 ...
- JAVA跑马灯实现1
<TextView android:layout_width="wrap_content" android:layout_height=" ...
- 了解php面向对象
php 三大特性:封装.继承.多态,一直以来只知道其字,却不大了解其意思和具体使用,只是对继承有大概的了 解,优点是代码的重用性,oop概念,记得有一次我去面试,人家问我什么是oop,然后我答了很多什 ...
- 【转】iOS开发UI篇—程序启动原理和UIApplication
原文 http://www.cnblogs.com/wendingding/p/3766347.html 一.UIApplication 1.简单介绍 (1)UIApplication对象是应用程 ...
- C# List
命名空间:using System.Collections; class Program {//做个比较 static void Main(string[] args) { //new对象 Cls a ...
- html 5的localstorag
随着我们硬件技术的发展,浏览器本身的功能也愈发的完善,从之前的cookie到现在的本地缓存机制,再到web storage,在之前html4 的时候使用cookie具有一些明显的局限,如大小限制,co ...
- for语句嵌套使用 实现9*9乘法表
这个实例主要考察对for循环语句的使用,出现递增规律的乘法表. 开发环境 开发工具:Microsoft Visual Studio2010 旗舰版 具体步骤 先是制作一个 ...