bzoj 1570: [JSOI2008]Blue Mary的旅行
Description
Input
Output
Sample Input
1 2 1
2 3 5
3 1 4
Sample Output
HINT
约定:
2 <= N <= 50
1 <= M <= 2450
1 <= T <= 50
1 <= X,Y <= N
X != Y
1 <= Z <= 50
Source
做过紧急疏散这个题就是一眼题了,考虑二分答案然后按时间拆点用判满流来check即可;
注意二分大上界为n+tot,因为tot个人排队走即可,一开始设为n*tot狂T不止;
//MADE BY QT666
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
const int N=200050;
const int Inf=19260817;
int head[N],to[N],nxt[N],s[N],S,T,cnt=1,level[N],vis[N],q[N*10],F,n,m,tot;
void Addedge(int x,int y,int z) {
to[++cnt]=y,s[cnt]=z,nxt[cnt]=head[x],head[x]=cnt;
}
void lnk(int x,int y,int z){
Addedge(x,y,z);Addedge(y,x,0);
}
bool bfs(){
for(int i=S;i<=T;i++) level[i]=0,vis[i]=0;
int t=0,sum=1;
q[0]=S,level[S]=1,vis[S]=1;
while(t<sum){
int now=q[t++];
if(now==T) return 1;
for(int i=head[now];i;i=nxt[i]){
int y=to[i];
if(level[y]==0&&s[i]){
level[y]=level[now]+1;
q[sum++]=y;
}
}
}
return 0;
}
int dfs(int now,int maxf){
if(now==T) return maxf;
int ret=0;
for(int i=head[now];i;i=nxt[i]) {
int y=to[i],f=s[i];
if(level[y]==level[now]+1&&f) {
int minn=min(maxf-ret,f);
f=dfs(y,minn);
s[i]-=f;s[i^1]+=f;ret+=f;
if(ret==maxf) break;
}
}
if(!ret) level[now]=0;
return ret;
}
void Dinic(){
while(bfs()) F+=dfs(S,Inf);
}
struct data{
int to,lim;
};
vector<data> p[100];
struct date{
int id[2505];
}g[100];
bool check(int mid){
memset(head,0,sizeof(head));cnt=1;int tt=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=mid;j++) g[i].id[j]=++tt;
}
S=0,T=tt+1;
for(int i=1;i<=n;i++){
for(int j=0;j<p[i].size();j++){
int x=p[i][j].to,lim=p[i][j].lim;
for(int k=0;k<mid;k++){
lnk(g[i].id[k],g[x].id[k+1],lim);
}
}
for(int k=0;k<mid;k++) lnk(g[i].id[k],g[i].id[k+1],Inf);
}
lnk(S,g[1].id[0],tot);
for(int i=0;i<=mid;i++) lnk(g[n].id[i],T,Inf);
F=0;Dinic();
return F==tot;
}
int main(){
scanf("%d%d%d",&n,&m,&tot);
for(int i=1;i<=m;i++){
int x,y,z;scanf("%d%d%d",&x,&y,&z);
p[x].push_back((data){y,z});
}
int l=0,r=n+tot,ans=0;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) r=mid-1,ans=mid;
else l=mid+1;
}
printf("%d\n",ans);
return 0;
}
bzoj 1570: [JSOI2008]Blue Mary的旅行的更多相关文章
- BZOJ 1570: [JSOI2008]Blue Mary的旅行( 二分答案 + 最大流 )
二分答案, 然后对于答案m, 把地点分成m层, 对于边(u, v), 第x层的u -> 第x+1层的v 连边. 然后第x层的u -> 第x+1层的u连边(+oo), S->第一层的1 ...
- bzoj1570: [JSOI2008]Blue Mary的旅行(二分+网络流)
1570: [JSOI2008]Blue Mary的旅行 题目:传送门 题解: get到拆点新姿势,还是做题太少了...ORZ 因为每天就只能有一个航班,那就不能直接连了,所以要拆点(然后就被卡住了) ...
- [BZOJ 1568][JSOI2008]Blue Mary开公司
[BZOJ 1568][JSOI2008]Blue Mary开公司 题意 \(n\) 次操作, 维护一个一次函数集合 \(S\). 有两种操作: 给定 \(b\) 和 \(k\), 向 \(S\) 中 ...
- 【BZOJ1570】[JSOI2008]Blue Mary的旅行 动态加边网络流
[BZOJ1570][JSOI2008]Blue Mary的旅行 Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决 ...
- 数据结构(线段树):BZOJ 1568 [JSOI2008]Blue Mary开公司
1568: [JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 602 Solved: 214[Submit ...
- BZOJ 1567: [JSOI2008]Blue Mary的战役地图( 二分答案 + hash )
二分答案, 然后用哈希去判断... ------------------------------------------------------------------------- #include ...
- bzoj 1568 [JSOI2008]Blue Mary开公司 超哥线段树
[JSOI2008]Blue Mary开公司 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1808 Solved: 639[Submit][Sta ...
- BZOJ 1567: [JSOI2008]Blue Mary的战役地图
1567: [JSOI2008]Blue Mary的战役地图 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1011 Solved: 578[Sub ...
- BZOJ 1567: [JSOI2008]Blue Mary的战役地图 矩阵二维hash
1567: [JSOI2008]Blue Mary的战役地图 Description Blue Mary最近迷上了玩Starcraft(星际争霸) 的RPG游戏.她正在设法寻找更多的战役地图以进一步提 ...
随机推荐
- Could not resolve view with name '***' in servlet with name 'dispatcher'
今天在开发中遇到了一个问题,控制层使用的是SpringMVC框架. @RequestMapping("historyDetail") private String History( ...
- Cracking the Coding Interview 题目分析笔记—— Array and String
1.Determine if a string has all unique characters learn: 为了减少空间利用率,其比较优秀的算法一般都适用位操作 返回值的命名方法,我们需要学习 ...
- POJ 1151 Wormholes spfa+反向建边+负环判断+链式前向星
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 49962 Accepted: 18421 Descr ...
- 初窥c++11:lambda函数及其用法
转载于:点击打开链接 为什么需要lambda函数 匿名函数是许多编程语言都支持的概念,有函数体,没有函数名.1958年,lisp首先采用匿名函数,匿名函数最常用的是作为回调函数的值.正因为有这样的需求 ...
- PHP实现的进度条效果详解
<?php //防止执行超时 set_time_limit(0); //清空并关闭输出缓存 ob_end_clean(); //需要循环的数据 for($i = 0; $i < 188 ...
- angularJS简单调用接口,实现数组页面打印
相比较jquery ,angular对这种接口数据处理起来会方便的多.这里举例调用 中国天气网的api接口. 首先肯定要引入angular.js这个不多说 <link rel="sty ...
- Require,js配置使用心得
首先大家要知道requirejs是干嘛用的,要解释,那就用一句话说下:RequireJS是一个JavaScript文件和模块加载器接下来我们开始学会配置使用requireJs,当然在学习使用的过程中也 ...
- How to get table pg_stat_user_functions.
修改配置文件postgres.conf track_functions = all # none, pl, all 或者 在当前事物中设置 postgres=# s ...
- ElasticSearch 学习记录之ES几种常见的聚合操作
ES几种常见的聚合操作 普通聚合 POST /product/_search { "size": 0, "aggs": { "agg_city&quo ...
- Selenium中如何使用xpath更快定位
在学习Selenium路上,踩了也不少坑,这是我最近才发现的一个新写法,好吧,"才发现"又说明我做其他事了.对的,我现在还在加班! 开车~~~ 例子:知乎网 标签:Python3. ...