题目链接:

  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)的更多相关文章

  1. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  2. 【线段树】BAPC2014 E Excellent Engineers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  3. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  4. 【宽搜】BAPC2014 J Jury Jeopardy (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  5. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  6. 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  7. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  8. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  9. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

随机推荐

  1. MVC ViewEngine视图引擎解读及autofac的IOC运用实践

    MVC 三大特色  Model.View.Control ,这次咱们讲视图引擎ViewEngine 1.首先看看IViewEngine接口的定义 namespace System.Web.Mvc { ...

  2. PageMapAdapter MapAdapter (续webServices)

    public class PageMapAdapter extends XmlAdapter<PageMapConverter, IPage<Map<String, Object&g ...

  3. javascript基础学习(五)

    javascript之函数 学习要点: 函数的介绍 函数的参数 函数的属性和方法 系统函数 一.函数的介绍 1.函数就是一段javascript代码.可以分为用户自定义函数和系统函数.   如果一个函 ...

  4. SGU 125.Shtirlits

    时间限制:0.25s 空间限制:4M 题意: 有N*N的矩阵(n<=3),对所有i,j<=n有G[i][j]<=9,定义f[i][j]为G[i][j]四周大于它的数的个数(F[i][ ...

  5. 原型链和new

    http://www.cnblogs.com/objectorl/archive/2010/01/11/Object-instancof-Function-clarification.html 构造器 ...

  6. Linux操作:

    1.在Linux中第一个字符代表这个文件是目录.文件或链接文件等等. 当为[ d ]则是目录,当为[ - ]则是文件,若是[ l ]则表示为链接文档(link file),若是[ b ]则表示为装置文 ...

  7. PHP图片操作

    <?php $filename="http://pic.nipic.com/2007-12-06/2007126102233577_2.jpg";//图片地址//获取图片信息 ...

  8. PHP常用代码:

    1.$array=explode(separator,$string); //字符串->数组 2.$string=implode(glue,$array);//数组->字符串 3.file ...

  9. php流行笔试题及答案

    1.在PHP中,当前脚本的名称(不包括路径和查询字符串)记录在预定义变量(1)中:而链接到当前页面的URL记录在预定义变量(2)中. 答:echo $_SERVER['PHP_SELF']; echo ...

  10. ueditor的过滤、转义、格式丢失问题

    1. 过滤 http://www.cnblogs.com/Olive116/p/3464495.html 2. 转义 http://segmentfault.com/q/101000000048928 ...