BZOJ1570 [JSOI2008]Blue Mary的旅行
建分层图,每一层表示一天的情况
从S向第0层的1号点连边,每层的n向T连INF的边
枚举天数,每多一天就多建一层然后跑最大流,如果当前流量大于人数则输出答案
由于路径长度不会超过n,因此tot个人走这条路径总天数不会超过tot + n,故只需要建tot + n层即可
/**************************************************************
Problem: 1570
User: rausen
Language: C++
Result: Accepted
Time:24 ms
Memory:15936 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int N = ;
const int M = ;
const int inf = 1e8; inline int read() {
int x = ;
char ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
} struct Edge {
int x, y, z; inline void read_in() {
x = read(), y = read(), z = read();
}
} E[M]; struct edge {
int next, to, f;
edge() {}
edge(int _n, int _t, int _f) : next(_n), to(_t), f(_f) {}
} e[M << ]; int n, m, t;
int S, T, ans;
int first[M], tot = ;
int d[M], q[M]; inline void Add_Edges(int x, int y, int f) {
e[++tot] = edge(first[x], y, f), first[x] = tot;
e[++tot] = edge(first[y], x, ), first[y] = tot;
} #define y e[x].to
#define p q[l]
bool bfs() {
int l, r, x;
memset(d, -, sizeof(d));
d[q[] = S] = ;
for (l = r = ; l != r + ; ++l)
for (x = first[p]; x; x = e[x].next)
if (!~d[y] && e[x].f) {
d[q[++r] = y] = d[p] + ;
if (y == T) return ;
}
return ;
}
#undef p int dfs(int p, int lim) {
if (p == T || !lim) return lim;
int x, tmp, rest = lim;
for (x = first[p]; x && rest; x = e[x].next)
if (d[y] == d[p] + && ((tmp = min(e[x].f, rest)) > )) {
rest -= (tmp = dfs(y, tmp));
e[x].f -= tmp, e[x ^ ].f += tmp;
if (!rest) return lim;
}
if (rest) d[p] = -;
return lim - rest;
}
#undef y int Dinic() {
int res = ;
while (bfs())
res += dfs(S, inf);
return res;
} int main() {
int i, j;
n = read(), m = read(), t = read();
for (i = ; i <= m; ++i) E[i].read_in();
S = , T = ;
Add_Edges(S, , t);
for (i = ; i <= n + t; ++i) {
for (j = ; j <= m; ++j)
Add_Edges(i * n - n + E[j].x + , i * n + E[j].y + , E[j].z);
for (j = ; j <= n; ++j)
Add_Edges(i * n - n + j + , i * n + j + , inf);
Add_Edges(i * n + n + , T, inf);
ans += Dinic();
if (ans == t) {
printf("%d\n", i);
return ;
}
}
}
BZOJ1570 [JSOI2008]Blue Mary的旅行的更多相关文章
- bzoj1570: [JSOI2008]Blue Mary的旅行(二分+网络流)
1570: [JSOI2008]Blue Mary的旅行 题目:传送门 题解: get到拆点新姿势,还是做题太少了...ORZ 因为每天就只能有一个航班,那就不能直接连了,所以要拆点(然后就被卡住了) ...
- 【BZOJ1570】[JSOI2008]Blue Mary的旅行 动态加边网络流
[BZOJ1570][JSOI2008]Blue Mary的旅行 Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决 ...
- bzoj 1570: [JSOI2008]Blue Mary的旅行
Description 在一段时间之后,网络公司终于有了一定的知名度,也开始收到一些订单,其中最大的一宗来自B市.Blue Mary决定亲自去签下这份订单.为了节省旅行经费,他的某个金融顾问建议只购买 ...
- 【bzoj1507】 JSOI2008—Blue Mary的旅行
http://www.lydsy.com/JudgeOnline/problem.php?id=1570 (题目链接) 题意 给出$m$个航班,每天只能做一次飞机,有$T$人从起点到终点,问最晚到达的 ...
- 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\)那么小,就知道是网络流.然后二分,按时间拆点. 刚开始我看成所有航班一天只能起飞一次,纠结了好一会儿.但实际上是每一个航班单独考虑,互不影响. 建图很显然,拆完点后每一个点的第\( ...
- 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 ...
随机推荐
- 测算Redis处理实际生产请求的QPS/TPS
测算Redis处理实际生产请求的QPS/TPS Benchmark工具 redis发布版本中自带了redis-benchmark性能测试工具; 示例: 使用50个并发连接,发出100000个请求,每个 ...
- CSS笔记(八)表格
参考:http://www.w3school.com.cn/css/css_table.asp 实例: <html> <head> <style type="t ...
- win8和ubuntu双系统安装
做了一个windows和Ubuntu双系统,参考了一些文章.网上资料不少,我就不重复了. 虽然没什么难度,但是有些细节在装的时候需要注意.不然造成资料丢失,系统崩溃,你就得不偿失,需要折腾花费较长的时 ...
- iOS - OC NSTimer 定时器
前言 @interface NSTimer : NSObject 作用 在指定的时间执行指定的任务. 每隔一段时间执行指定的任务. 1.定时器的创建 当定时器创建完(不用 scheduled 的,添加 ...
- [转载] 分享D瓜哥最近攒的资料(架构方面)
原文: http://www.diguage.com/archives/41.html 扯扯蛋 以前见过零零散散地介绍一些知名网站架构的分析文章.最近D瓜哥也想研究一下各大知名网站的架构.所以,就搜集 ...
- curl的简单使用
<?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { ...
- Android notifications通知栏的使用
app发送通知消息到通知栏中的关键代码和点击事件: package com.example.notifications; import android.os.Bundle; import androi ...
- h5 input file ajax实现文件上传
<input type="file" accept="image/*" height="0" class="file_inp ...
- 原创: 开题报告中摘要部分快速将一段文字插入到word的表格中
开题报告的摘要是表格形式,之前需要一个一个字的敲入,十分不方便修改. 所以百度了一下方法.现总结如下: 达到的效果 1 将这段文字复制粘贴到word中,在word文件中的每一个字与字之间插入空格.如何 ...
- The Zen Programmer (zhuan)
http://blog.csdn.NET/marksinoberg/article/details/52460725 ***************************************** ...