[JSOI2008]Blue Mary的旅行
嘟嘟嘟
看\(n\)那么小,就知道是网络流。然后二分,按时间拆点。
刚开始我看成所有航班一天只能起飞一次,纠结了好一会儿。但实际上是每一个航班单独考虑,互不影响。
建图很显然,拆完点后每一个点的第\(i\)天向和他相连的点的第\(i + 1\)天连边,同时自己的第\(i\)天也要向第\(i + 1\)天连边。
刚开始数组开小了,自己造了几组大数据才对。不过说来也奇怪,自己的随机数据跑出来都3、4秒,交上去却秒A了。可能是因为自己的答案都是1或2吧,出题人为了防止固输骗分,就没有造这种极端数据。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 62505;
const int maxe = 1e6 + 5;
const int maxm = 2455;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n, m, tot, t;
struct Node
{
int x, y, w;
}ed[maxm];
struct Edge
{
int nxt, to, cap, flow;
}e[maxe];
int head[maxn], ecnt = -1;
In void addEdge(int x, int y, int w)
{
//printf("()%d %d %d\n", x, y, w);
e[++ecnt] = (Edge){head[x], y, w, 0};
head[x] = ecnt;
e[++ecnt] = (Edge){head[y], x, 0, 0};
head[y] = ecnt;
}
int dis[maxn];
In bool bfs()
{
Mem(dis, 0); dis[0] = 1;
queue<int> q; q.push(0);
while(!q.empty())
{
int now = q.front(); q.pop();
//printf("#%d\n", now);
for(int i = head[now], v; ~i; i = e[i].nxt)
{
if(!dis[v = e[i].to] && e[i].cap > e[i].flow)
{
dis[v] = dis[now] + 1;
q.push(v);
}
}
}
return dis[t];
}
int cur[maxn];
In int dfs(int now, int res)
{
if(now == t || res == 0) return res;
int flow = 0, f;
for(int& i = cur[now], v; ~i; i = e[i].nxt)
{
if(dis[v = e[i].to] == dis[now] + 1 && (f = dfs(v, min(res, e[i].cap - e[i].flow))) > 0)
{
e[i].flow += f, e[i ^ 1].flow -= f;
flow += f, res -= f;
if(res == 0) break;
}
}
return flow;
}
In int maxflow()
{
int flow = 0;
while(bfs())
{
memcpy(cur, head, sizeof(head));
flow += dfs(0, INF);
}
return flow;
}
int _Max = 0;
In int num(int x, int tim, int id) {return (x - 1) * tim + id;}
In bool judge(int tim)
{
ecnt = -1; Mem(head, -1);
t = num(n, tim, tim) + 1;
_Max = max(_Max, t);
for(int i = 1; i <= m; ++i)
for(int j = 1; j < tim; ++j) addEdge(num(ed[i].x, tim, j), num(ed[i].y, tim, j + 1), ed[i].w);
for(int i = 1; i <= tim; ++i)
{
addEdge(0, num(1, tim, i), INF);
addEdge(num(n, tim, i), t, INF);
}
for(int i = 1; i <= n; ++i)
for(int j = 2; j <= tim; ++j) addEdge(num(i, tim, j - 1), num(i, tim, j), INF);
return maxflow() >= tot;
}
int main()
{
//freopen("ha.in", "r", stdin);
Mem(head, -1);
n = read(), m = read(), tot = read();
for(int i = 1; i <= m; ++i) ed[i].x = read(), ed[i].y = read(), ed[i].w = read();
int L = 0, R = tot * n + 1;
while(L < R)
{
int mid = (L + R) >> 1;
if(judge(mid)) R = mid;
else L = mid + 1;
}
write(L - 1), enter;
//write(_Max), enter;
return 0;
}
[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决定亲自去签下这份订单.为了节省旅行经费,他的某个金融顾问建议只购买 ...
- 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 ...
- 【bzoj1507】 JSOI2008—Blue Mary的旅行
http://www.lydsy.com/JudgeOnline/problem.php?id=1570 (题目链接) 题意 给出$m$个航班,每天只能做一次飞机,有$T$人从起点到终点,问最晚到达的 ...
- bzoj1567: [JSOI2008]Blue Mary的战役地图
将矩阵hash.s[0]忘了弄成0,输出中间过程发现了. hash.sort.判重.大概这样子的步骤吧. #include<cstdio> #include<cstring> ...
- 数据结构(线段树):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 ...
随机推荐
- pytest之收集用例规则与运行指定用例
前言 上篇文章相信大家已经了解了pytest在cmd下结合各种命令行参数如何运行测试用例,并输出我们想要看到的信息.那么今天会讲解一下pytest是如何收集我们写好的用例?我们又有哪些方式来运行单个用 ...
- linux中使用docker-compose部署软件配置分享
本篇将分享一些 docker-compose 的配置,可参考其总结自己的一套基于docker的开发/生产环境配置. 安装docker及docker-compose install docker cur ...
- 为 VUE 项目添加 PWA 解决发布后刷新报错问题
为什么要给 VUE 项目添加 PWA 为什么要添加?因为不管是部署在 IIS,还是 nginx,每次应用部署后,再次访问因为旧的 js 已经不存在,所以页面访问的时候会整个报错,报错的结果就是一个白屏 ...
- 从壹开始微服务 [ DDD ] 之三 ║ 简单说说:领域、子域、限界上下文
前言 哈喽大家好,DDD领域驱动设计系列又开始了,前天周二的那篇入门文章中,也收到了一定的效果(写小说的除外),同时我也是倍感鸭梨,怎么说呢,DDD领域驱动设计已经有十年历史了,甚至更久,但是包括我在 ...
- 死磕 java集合之ConcurrentHashMap源码分析(三)
本章接着上两章,链接直达: 死磕 java集合之ConcurrentHashMap源码分析(一) 死磕 java集合之ConcurrentHashMap源码分析(二) 删除元素 删除元素跟添加元素一样 ...
- TabLayoutViewPagerDemo【TabLayout+ViewPager可滑动】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 使用TabLayout搭配ViewPager实现可滑动的顶部选项卡效果. 效果图 代码分析 1.演示常规的设置. 2.通过自定义Vi ...
- springboot~@Valid注解对嵌套类型的校验
@Valid注解可以实现数据的验证,你可以定义实体,在实体的属性上添加校验规则,而在API接收数据时添加@valid关键字,这时你的实体将会开启一个校验的功能,具体的代码如下,是最基本的应用: 实体: ...
- 每周分享五个 PyCharm 使用技巧(二)
这是 「PyCharm 技巧分享」系列的第二篇分享.由于上一篇文章得到了大家的一些赞同,所以今天又来给大家推荐一些我平时自己有用的小技巧,大家择需所取即可. 先声明下,并不保证对所有的人都是有帮助的, ...
- C# 插入文本框到PPT幻灯片
概述 在文本框中我们可以实现的操作有很多,如插入文字.图片.设置字体大小.颜色.文本框背景填充.边框设置等.下面的示例中,将介绍通过C# 在PPT幻灯片中插入幻灯片的方法. 示例中包含了以下要点: 插 ...
- 移动端video不全屏播放
<div class="m-video"> <video x5-playsinline="" playsinline="" ...