「JSOI2008」Blue Mary的旅行
传送门
Luogu
解题思路
分层图加网络流,有点像这题
可以证明最多不超过100天,所以才可以分层,不然图的规模会很大。
首先连源点汇点: \((s,1,INF), (n, t, INF)\)
以时间分层,每次把原图中的边 \((u, v, w)\) 改为一条 \((u_{day1}, v_{day2}, w)\) 的弧。
对于 \(u < n\),连一条弧 \((u_{day1}, u_{day2}, INF)\),以及一条 \((n_{day2}, n_{day1}, INF)\)。
然后每次在残量网络上加边增广直至最大流大于等于 \(T\)。
细节注意事项
- 每次增广时都要把流量累加
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
const int _ = 5010;
const int __ = 250010;
const int INF = 2147483647;
int tot = 1, head[_], nxt[__ << 1], ver[__ << 1], cap[__ << 1];
inline void Add_edge(int u, int v, int d)
{ nxt[++tot] = head[u], head[u] = tot, ver[tot] = v, cap[tot] = d; }
inline void link(int u, int v, int d) { Add_edge(u, v, d), Add_edge(v, u, 0); }
int n, m, k, s, t, dep[_], cur[_];
struct node { int u, v, d; } x[2452];
inline int id(int u, int d) { return u + (d - 1) * n; }
inline int bfs() {
static queue < int > Q;
memset(dep, 0, sizeof dep);
dep[s] = 1, Q.push(s);
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (rg int i = head[u]; i; i = nxt[i]) {
int v = ver[i];
if (dep[v] == 0 && cap[i] > 0)
dep[v] = dep[u] + 1, Q.push(v);
}
}
return dep[t] > 0;
}
inline int dfs(int u, int flow) {
if (u == t) return flow;
for (rg int& i = cur[u]; i; i = nxt[i]) {
int v = ver[i];
if (dep[v] == dep[u] + 1 && cap[i] > 0) {
int res = dfs(v, min(flow, cap[i]));
if (res) { cap[i] -= res, cap[i ^ 1] += res; return res; }
}
}
return 0;
}
inline int Dinic(int day) {
int res = 0;
while (bfs()) {
cur[s] = head[s], cur[t] = head[t];
for (rg int x = 1; x <= day; ++x)
for (rg int i = 1; i <= n; ++i)
cur[id(i, x)] = head[id(i, x)];
while (int d = dfs(s, INF)) res += d;
}
return res;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(m), read(k);
for (rg int i = 1; i <= m; ++i)
read(x[i].u), read(x[i].v), read(x[i].d);
s = _ - 1, t = _ - 2;
link(s, id(1, 1), INF);
link(id(n, 1), t, INF);
int res = 0;
for (rg int d = 2; ; ++d) {
for (rg int i = 1; i <= m; ++i)
link(id(x[i].u, d - 1), id(x[i].v, d), x[i].d);
for (rg int i = 1; i < n; ++i)
link(id(i, d - 1), id(i, d), INF);
link(id(n, d), id(n, d - 1), INF);
res += Dinic(d);
if (res >= k) { printf("%d\n", d - 1); return 0; }
}
return 0;
}
完结撒花 \(qwq\)
「JSOI2008」Blue Mary的旅行的更多相关文章
- 【BZOJ1570】[JSOI2008]Blue Mary的旅行 动态加边网络流
[BZOJ1570][JSOI2008]Blue Mary的旅行 Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决 ...
- bzoj1570: [JSOI2008]Blue Mary的旅行(二分+网络流)
1570: [JSOI2008]Blue Mary的旅行 题目:传送门 题解: get到拆点新姿势,还是做题太少了...ORZ 因为每天就只能有一个航班,那就不能直接连了,所以要拆点(然后就被卡住了) ...
- bzoj 1570: [JSOI2008]Blue Mary的旅行
Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决定亲自去签下这份订单.为了节省旅行经费,他的某个金融顾问建议只购买 ...
- [JSOI2008] [BZOJ1567] Blue Mary的战役地图 解题报告 (hash)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1567 Description Blue Mary最近迷上了玩Starcraft(星际争霸 ...
- BZOJ1570 [JSOI2008]Blue Mary的旅行
建分层图,每一层表示一天的情况 从S向第0层的1号点连边,每层的n向T连INF的边 枚举天数,每多一天就多建一层然后跑最大流,如果当前流量大于人数则输出答案 由于路径长度不会超过n,因此tot个人走这 ...
- BZOJ 1570: [JSOI2008]Blue Mary的旅行( 二分答案 + 最大流 )
二分答案, 然后对于答案m, 把地点分成m层, 对于边(u, v), 第x层的u -> 第x+1层的v 连边. 然后第x层的u -> 第x+1层的u连边(+oo), S->第一层的1 ...
- [JSOI2008]Blue Mary的旅行
嘟嘟嘟 看\(n\)那么小,就知道是网络流.然后二分,按时间拆点. 刚开始我看成所有航班一天只能起飞一次,纠结了好一会儿.但实际上是每一个航班单独考虑,互不影响. 建图很显然,拆完点后每一个点的第\( ...
- 【bzoj1507】 JSOI2008—Blue Mary的旅行
http://www.lydsy.com/JudgeOnline/problem.php?id=1570 (题目链接) 题意 给出$m$个航班,每天只能做一次飞机,有$T$人从起点到终点,问最晚到达的 ...
- LG1198/BZOJ1012 「JSOI2008」最大数 线段树+离线
问题描述 LG1198 BZOJ1012 题解 我们把所有操作离线,设一共有\(n\)个插入操作. 于是提前建立\(n\)个数,全部设为\(-INF\) 接着逐个处理操作即可. \(\mathrm{C ...
随机推荐
- Maven中配置jdk的版本
在单个项目中配置 在maven项目的pom.xml文件中加入以下内容 <build> <plugins> <plugin> <groupId>org.a ...
- P1157 组合的输出
P1157 组合的输出 #include <bits/stdc++.h> using namespace std; int n,r; int a[25]; vector<int> ...
- 【Java excel】导出excel文件
TestExprot package excel; import java.io.File; import java.io.IOException; import java.text.DateForm ...
- 2018 最新注册码【激活码】、在线激活 pycharm 完整方法(亲测有效)【2018.06.01 重大更新!!!!】
2018-06-01修改如下: 原来方法的第二种还是有效的,操作如下 (1)更新hosts文件(可以直接下载,然后解压缩) host文件地址 hosts文件,在windows中的地址为: 替换host ...
- Python3.5学习之旅——day5
模块初识 一.定义 在python中,模块是用来实现某一特定功能的代码集合.其本质上就是以‘.py’结尾的python文件.例如某文件名为test.py,则模块名为test. 二.导入方法 我们在这一 ...
- Scrapy 分布式爬取
由于受到计算机能力和网络带宽的限制,单台计算机运行的爬虫咋爬取数据量较大时,需要耗费很长时间.分布式爬取的思想是“人多力量大”,在网络中的多台计算机同时运行程序,公童完成一个大型爬取任务, Scrap ...
- nginx 的提升多个小文件访问的性能模块
阿里开源的第三方模块下载地址:https://github.com/alibaba/nginx-http-concat 下载模块 git clone https://github.com/alibab ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:联合使用所有表格类
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 显示代码:电脑程序输出: Sample output
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 牛客挑战赛36 G Nim游戏(分治FWT)
https://ac.nowcoder.com/acm/contest/3782/G 题解: 分治FWT裸题. 每个都相当于\((1+b[i]x^{a[i]})\),求这玩意的异或卷积. 先把a[i] ...