传送门

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\)。

细节注意事项

  • 每次增广时都要把流量累加

参考代码

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <cctype>
  7. #include <cmath>
  8. #include <ctime>
  9. #include <queue>
  10. #define rg register
  11. using namespace std;
  12. template < typename T > inline void read(T& s) {
  13. s = 0; int f = 0; char c = getchar();
  14. while (!isdigit(c)) f |= (c == '-'), c = getchar();
  15. while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
  16. s = f ? -s : s;
  17. }
  18. const int _ = 5010;
  19. const int __ = 250010;
  20. const int INF = 2147483647;
  21. int tot = 1, head[_], nxt[__ << 1], ver[__ << 1], cap[__ << 1];
  22. inline void Add_edge(int u, int v, int d)
  23. { nxt[++tot] = head[u], head[u] = tot, ver[tot] = v, cap[tot] = d; }
  24. inline void link(int u, int v, int d) { Add_edge(u, v, d), Add_edge(v, u, 0); }
  25. int n, m, k, s, t, dep[_], cur[_];
  26. struct node { int u, v, d; } x[2452];
  27. inline int id(int u, int d) { return u + (d - 1) * n; }
  28. inline int bfs() {
  29. static queue < int > Q;
  30. memset(dep, 0, sizeof dep);
  31. dep[s] = 1, Q.push(s);
  32. while (!Q.empty()) {
  33. int u = Q.front(); Q.pop();
  34. for (rg int i = head[u]; i; i = nxt[i]) {
  35. int v = ver[i];
  36. if (dep[v] == 0 && cap[i] > 0)
  37. dep[v] = dep[u] + 1, Q.push(v);
  38. }
  39. }
  40. return dep[t] > 0;
  41. }
  42. inline int dfs(int u, int flow) {
  43. if (u == t) return flow;
  44. for (rg int& i = cur[u]; i; i = nxt[i]) {
  45. int v = ver[i];
  46. if (dep[v] == dep[u] + 1 && cap[i] > 0) {
  47. int res = dfs(v, min(flow, cap[i]));
  48. if (res) { cap[i] -= res, cap[i ^ 1] += res; return res; }
  49. }
  50. }
  51. return 0;
  52. }
  53. inline int Dinic(int day) {
  54. int res = 0;
  55. while (bfs()) {
  56. cur[s] = head[s], cur[t] = head[t];
  57. for (rg int x = 1; x <= day; ++x)
  58. for (rg int i = 1; i <= n; ++i)
  59. cur[id(i, x)] = head[id(i, x)];
  60. while (int d = dfs(s, INF)) res += d;
  61. }
  62. return res;
  63. }
  64. int main() {
  65. #ifndef ONLINE_JUDGE
  66. freopen("in.in", "r", stdin);
  67. #endif
  68. read(n), read(m), read(k);
  69. for (rg int i = 1; i <= m; ++i)
  70. read(x[i].u), read(x[i].v), read(x[i].d);
  71. s = _ - 1, t = _ - 2;
  72. link(s, id(1, 1), INF);
  73. link(id(n, 1), t, INF);
  74. int res = 0;
  75. for (rg int d = 2; ; ++d) {
  76. for (rg int i = 1; i <= m; ++i)
  77. link(id(x[i].u, d - 1), id(x[i].v, d), x[i].d);
  78. for (rg int i = 1; i < n; ++i)
  79. link(id(i, d - 1), id(i, d), INF);
  80. link(id(n, d), id(n, d - 1), INF);
  81. res += Dinic(d);
  82. if (res >= k) { printf("%d\n", d - 1); return 0; }
  83. }
  84. return 0;
  85. }

完结撒花 \(qwq\)

「JSOI2008」Blue Mary的旅行的更多相关文章

  1. 【BZOJ1570】[JSOI2008]Blue Mary的旅行 动态加边网络流

    [BZOJ1570][JSOI2008]Blue Mary的旅行 Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决 ...

  2. bzoj1570: [JSOI2008]Blue Mary的旅行(二分+网络流)

    1570: [JSOI2008]Blue Mary的旅行 题目:传送门 题解: get到拆点新姿势,还是做题太少了...ORZ 因为每天就只能有一个航班,那就不能直接连了,所以要拆点(然后就被卡住了) ...

  3. bzoj 1570: [JSOI2008]Blue Mary的旅行

    Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决定亲自去签下这份订单.为了节省旅行经费,他的某个金融顾问建议只购买 ...

  4. [JSOI2008] [BZOJ1567] Blue Mary的战役地图 解题报告 (hash)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1567 Description Blue Mary最近迷上了玩Starcraft(星际争霸 ...

  5. BZOJ1570 [JSOI2008]Blue Mary的旅行

    建分层图,每一层表示一天的情况 从S向第0层的1号点连边,每层的n向T连INF的边 枚举天数,每多一天就多建一层然后跑最大流,如果当前流量大于人数则输出答案 由于路径长度不会超过n,因此tot个人走这 ...

  6. BZOJ 1570: [JSOI2008]Blue Mary的旅行( 二分答案 + 最大流 )

    二分答案, 然后对于答案m, 把地点分成m层, 对于边(u, v), 第x层的u -> 第x+1层的v 连边. 然后第x层的u -> 第x+1层的u连边(+oo), S->第一层的1 ...

  7. [JSOI2008]Blue Mary的旅行

    嘟嘟嘟 看\(n\)那么小,就知道是网络流.然后二分,按时间拆点. 刚开始我看成所有航班一天只能起飞一次,纠结了好一会儿.但实际上是每一个航班单独考虑,互不影响. 建图很显然,拆完点后每一个点的第\( ...

  8. 【bzoj1507】 JSOI2008—Blue Mary的旅行

    http://www.lydsy.com/JudgeOnline/problem.php?id=1570 (题目链接) 题意 给出$m$个航班,每天只能做一次飞机,有$T$人从起点到终点,问最晚到达的 ...

  9. LG1198/BZOJ1012 「JSOI2008」最大数 线段树+离线

    问题描述 LG1198 BZOJ1012 题解 我们把所有操作离线,设一共有\(n\)个插入操作. 于是提前建立\(n\)个数,全部设为\(-INF\) 接着逐个处理操作即可. \(\mathrm{C ...

随机推荐

  1. pl/sql修改data

    1,对于语句要包含rowid!

  2. 【转载】IntelliJ IDEA配置JUnit进行单元测试

    前提条件 安装JDK,并配置好环境变量 工程已解决JUnit依赖关系(pom.xml) IDEA中JUnit配置 IDEA自带一个JUnit插件,打开Settings窗口搜索junit,如图:   图 ...

  3. [运维] 请求 nginx 出现 502 Bad Gateway 的解决方案!

    环境: 云服务器镜像 Linux CentOS 7.6 已经安装并成功配置 SSL 的 nginx 1.16.1 成功安装并且可以正常运行的 apache-tomcat-9.0.26 遇到的问题: 在 ...

  4. TortoiseGit 安装与配置

    2. TortoiseGit安装与配置 标签: TortoiseGit安装配置Windows 2014-12-01 15:25 135739人阅读 评论(10) 收藏 举报 .embody{ padd ...

  5. jquery移除click事件

    原文链接:https://blog.csdn.net/weixin_41228949/article/details/83142661 在html中定义click事件有两种方式,针对这两种方式有两种移 ...

  6. Matlab的简单数据保存读取

    1.使用load进行文件读取 例如读入文件名为'filename.txt'中的数据,那么可以使用以下代码: load('filename.txt') 注意:filename.txt中的数据应符合矩阵形 ...

  7. 攻防世界Web进阶-Upload1

    进入题目 题目提示上传文件,准备好一句话木马. 发现只能上传图片文件,那么再准备一个图片的一句话木马.上传. 浏览器开代理,使用burpsuite拦截,修改文件后缀名为php,否则无法连接 使用蚁剑连 ...

  8. tomcat注册为windows服务

    打开CMD,进入到Tomcat的bin目录,执行命令:service.bat install  [service_name] 如果卸载服务,可以执行:sc delete [service_name]

  9. gensim加载词向量文件

    # -*- coding: utf-8 -*- # author: huihui # date: 2020/1/31 7:58 下午 ''' 根据语料训练词向量,并保存向量文件 ''' import ...

  10. 【PAT甲级】1027 Colors in Mars (20 分)

    题意: 输入三个范围为0~168的整数,将它们从十三进制转化为十进制然后前缀#输出. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include& ...