【最大流】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$段,考虑最少能够减少多少划分 ...
随机推荐
- 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之一
/** ****************************************************************************** * @author 暴走的小 ...
- C#-日期格式表
自定义格式表: 格式模式 说明 d 月中的某一天.一位数的日期没有前导零. dd 月中的某一天.一位数的日期有一个前导零. ...
- 简单讲解iOS应用开发中的MD5加密的相关使用<转>
这篇文章主要介绍了iOS应用开发中的MD5加密的相关使用,示例代码基于传统的Objective-C,需要的朋友可以参考下 一.简单说明 1.说明 在开发应用的时候,数据的安全性至关重要,而仅仅用POS ...
- Windows2003 下 MySQL 数据库每天自动备份
1. 环境: windows server 2003 + Apache 2.0 + PHP5 + MySQL 4.0.26 . 2. 假设 PHP 安装目录为 D:/php ,MySQL 安装目录为 ...
- T-SQL语言基础
1.T-SQL语言 CREATE:创建新对象,包括数据库.表.视图.过程.触发器和函数等常见数据库对象. ALTER:修改已有对象的结构. DROP:用来删除已有的对象.有些对象是无法删除的,因为它们 ...
- login-登录
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Inse ...
- linuxC编程实战 my_server.c例子问题总结
今天看linux C 编程实战的my_server例子时,敲到这段代码,对其父子进程关闭socket 进行close调用产生疑问 如图中标注的三个close socket,思考子进程通信结束 关闭自己 ...
- js基础 - 兼容代码
js基础 - 兼容代码 . scrollTop . chrome document.body.scrollTop . IE && firefox document.documentEl ...
- Python自动化运维之30、Flask框架
Flask 官网:http://flask.pocoo.org/ flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是 ...
- fragment 学习
fragment需要id是必须属性 <fragment android:id="@+id/frg1" android:name="com ...