【最大流】BAPC2014 A Avoiding the Apocalypse (Codeforces GYM 100526)
题目链接:
http://codeforces.com/gym/100526
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11664&courseid=0
题目大意:
总共N个点,现在有P个人,在T时间内要从起点S走到C个医疗站中的任意一个,M条X到Y的有向边,每条边每个单位时间可以通过的人数是pi,走完这条边耗时ti。
人可以停留在任意一个点,求最多能有多少人到达医疗站。
(1<=C<=N<=1000,0<=M<=1000,1<=P,T<=100,1<=pi,ti<=100)
题目思路:
【最大流】
SPFA居然T了。。
将每个点按照时间拆点{X节点j时间的状态为点X(j)},把X到Y的边pi,ti拆成T-ti条边,每条边从X(j)到Y(j+ti)容量为pi,j为时间从0~T-ti,表示在j时间有pi个人可以从X到Y,到达Y的时间为j+ti。
因为人可以停留在节点上所以X(i)到X(i+1)连一条容量P的边。
每个医疗站的最终时间Ci(T)到超级汇T_T连一条容量为P的边(到达医疗站的人就无限停留直到时间为T到超级汇T_T)
超级源S_S到起点S(0)连一条容量为P的边表示初始起点S有P个人。
最终统计到达超级汇的人数即可。跑一遍最大流。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#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-8)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 1004
#define M 104
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int s,p,t,S,T,nn;
int c[N];
int last[N*M+M],vd[N*M+M],d[N*M+M];
struct xxx
{
int next,to,q;
}a[N*M*M];
void add(int x,int y,int f)
{
a[++lll].next=last[x];
a[lll].to=y;
a[lll].q=f;
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,f,dd;
for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s+1))
// while(~scanf("%d",&n))
{
ans=;lll=;mem(vd,);mem(d,);mem(last,);
scanf("%d%d%d%d%d",&n,&s,&p,&t,&cass);
S=n*t+t+;T=S+;
nn=T;vd[]=nn-t+;
add(S,t,p);
add(t,S,);
add(t,s*t+,p);
add(s*t+,t,);
for(i=;i<=n;i++)
{
for(j=;j<t;j++)
{
add(i*t+j,i*t+j+,p);
add(i*t+j+,i*t+j,);
}
}
for(i=;i<=cass;i++)
{
scanf("%d",&c[i]);
add(c[i]*t+t,T,p);
add(T,c[i]*t+t,);
}
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d%d%d%d",&x,&y,&f,&dd);
for(j=;j+dd<=t;j++)
{
add(x*t+j,y*t+j+dd,f);
add(y*t+j+dd,x*t+j,);
}
if(x==s)
{
add(t,y*t+dd,f);
add(y*t+dd,t,);
}
}
while(d[S]<nn)
{
f=sap(S,MAX);
ans+=f;
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/
【最大流】BAPC2014 A Avoiding the Apocalypse (Codeforces GYM 100526)的更多相关文章
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【宽搜】BAPC2014 J Jury Jeopardy (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
随机推荐
- Winform 程序中dll程序集嵌入exe可执行文件
关于这方面,Google一下有很多方法,参考: http://blog.csdn.net/astonqa/article/details/7300856 但按照以上的方法我并没有成功,于是继续找到了一 ...
- 我是一块cpu 《转载》
我是一块cpu,原装intel,在一台普通的台式计算机里供职.我有个小弟是内存,我要靠他时时刻刻陪伴我工作,其实有时候我并不是没有某某地址的资料,而是懒得翻--麻烦. 还有一个老大哥叫bios,每次那 ...
- asp.net手动填充TreeView生成树
最近在做项目发现需要用到树的地方,页面的前台任然是使用一个asp.net的控件TreeView来显示树的结构,当然也可以自己在前台写一个树来展示,这在后期跟局功能的不同很大可能会要用到异步的知识,废话 ...
- Datatables+Bootstrap
http://sandbox.runjs.cn/show/thwac3ec 运行效果 <!DOCTYPE html> <html lang="en"> &l ...
- JavaScript 计时事件
JavaScript 计时事件 通过使用 JavaScript,我们有能力作到在一个设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行.我们称之为计时事件. 在 JavaScritp 中使用计 ...
- 异步IO简介
最近想学习一下libevent,就先翻译一下libevent的官方文档吧. 英文原文链接:http://www.wangafu.net/~nickm/libevent-book/01_intro.ht ...
- 【vc】14_网络编程_socket编程
1.计算机网络基本知识 最简单的网络程序如图: 提示:IP地址就相当于一个公司的总机号码,端口号就相当于分机号码.在打电话时,拨通总机后,还需要转到分机上. (1)协议 ·为进行网络中的数据交换(通信 ...
- ios开发之IBOutlet和IBAction的区别
IBOutlet 输出口是使用关键字IBOutlet声明的实例变量.控制器头文件中的输出口声明应如下所示: @property (nonatomic, retain) IBOutlet UIButto ...
- C# winform DataGridView操作 (转)
C# DataGridView控件动态添加新行 DataGridView控件在实际应用中非常实用,特别需要表格显示数据时.可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行.假如 ...
- yii2源码学习笔记(四)
继续了解组件Component.php /** * Returns a value indicating whether a property is defined for this componen ...