【BZOJ】2929: [Poi1999]洞穴攀行(最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=2929
题意描述不清。。搞得我wa了一发。。
应该是,有1和n的点的边容量都为1,其余随便。。。
然后是裸题。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const int N=415, oo=~0u>>1;
int ihead[N], cnt=1;
struct dat { int next, to, from, cap; }e[N*N*2];
void add(int u, int v, int c) {
e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].from=u; e[cnt].to=v; e[cnt].cap=c;
e[++cnt].next=ihead[v]; ihead[v]=cnt; e[cnt].from=v; e[cnt].to=u; e[cnt].cap=0;
}
int p[N], d[N], gap[N], cur[N];
int isap(int s, int t, int n) {
for1(i, 0, n) p[i]=0, d[i]=0, gap[i]=0, cur[i]=ihead[i];
gap[0]=n; int ret=0, f, u=s, i;
while(d[s]<n) {
for(i=cur[u]; i; i=e[i].next) if(e[i].cap && d[e[i].to]+1==d[u]) break;
if(i) {
p[e[i].to]=cur[u]=i; u=e[i].to;
if(u==t) {
for(f=oo; u!=s; u=e[p[u]].from) f=min(f, e[p[u]].cap);
for(u=t; u!=s; u=e[p[u]].from) e[p[u]].cap-=f, e[p[u]^1].cap+=f;
ret+=f;
}
}
else {
if(!(--gap[d[u]])) break;
d[u]=n; cur[u]=ihead[u];
for(i=ihead[u]; i; i=e[i].next) if(e[i].cap && d[e[i].to]+1<d[u]) d[u]=d[e[i].to]+1;
++gap[d[u]];
if(u!=s) u=e[p[u]].from;
}
}
return ret;
} int n;
int main() {
read(n);
for1(i, 1, n-1) {
int k=getint();
while(k--) {
int t=getint();
if(i==1 || t==n) add(i, t, 1);
else add(i, t, oo);
}
}
printf("%d\n", isap(1, n, n));
return 0;
}
Description
Input
Output
Sample Input
4 3 4 2 5
1 8
2 9 7
2 6 11
1 8
2 9 10
2 10 11
1 12
2 10 12
1 12
1 12
Sample Output
HINT
Source
【BZOJ】2929: [Poi1999]洞穴攀行(最大流)的更多相关文章
- BZOJ 2929: [Poi1999]洞穴攀行
2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 351 Solved: 195[Submit][Status][ ...
- bzoj 2929 [Poi1999]洞穴攀行 网络流
2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 499 Solved: 295[Submit][Status][ ...
- 2929: [Poi1999]洞穴攀行
2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 41[Submit][Status][Di ...
- 【bzoj2929】[Poi1999]洞穴攀行 网络流最大流
题目描述 洞穴学者在Byte Mountain的Grate Cave里组织了一次训练.训练中,每一位洞穴学者要从最高的一个室到达最底下的一个室.他们只能向下走.一条路上每一个连续的室都要比它的前一个低 ...
- 【最大流】【Dinic】bzoj2929 [Poi1999]洞穴攀行
TMD 题意其实是与1或n相连的边只能走一次,其他可以走无限次……翻译去死. 裸最大流. #include<cstdio> #include<cstring> #include ...
- bzoj2929 [Poi1999]洞穴攀行
Description 一队洞穴学者在Byte Mountain的Grate Cave里组织了一次训练.训练中,每一位洞穴学者要从最高的一个室到达最底下的一个室.他们只能向下走.一条路上每一个连续的室 ...
- BZOJ 3876 支线剧情 | 有下界费用流
BZOJ 3876 支线剧情 | 有下界费用流 题意 这题题面搞得我看了半天没看懂--是这样的,原题中的"剧情"指的是边,"剧情点"指的才是点. 题面翻译过来大 ...
- 从多种角度看[BZOJ 1061] [NOI 2008]志愿者招募(费用流)
从多种角度看[BZOJ 1061] [NOI 2008]志愿者招募(费用流) 题面 申奥成功后,布布经过不懈努力,终于成为奥组委下属公司人力资源部门的主管.布布刚上任就遇到了一个难题:为即将启动的奥运 ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
随机推荐
- PHP读取csv文件
<?php //取数据 $f_d = file_get_contents('tpl_import_info.csv'); $f_d = iconv('gbk', 'utf-8', $f_d); ...
- 61. 从1到n,共有n个数字,每个数字只出现一次。从中随机拿走一个数字x,请给出最快的方法,找到这个数字。如果随机拿走k(k>=2)个数字呢?[find k missing numbers from 1 to n]
[本文链接] http://www.cnblogs.com/hellogiser/p/find-k-missing-numbers-from-1-to-n.html [题目] 从1到n,共有n个数字 ...
- Android 中获得notification的发出时间
最近做程序时,有一个类似闹钟的功能,用notification唤醒程序后,希望能得到发出这个notification时的具体时间,就是notification右边写着的那个时间.查了notificat ...
- eclipse 切换svn账号
1. 查看你的Eclipse中使用的是什么SVN Interface,位置在 windows > preference > Team > SVN 2. 如果是用的J ...
- Redhat修改主机名_Red hat怎么永久修改主机名hostname(转)
有几种方式修改Redhat的主机名字,这些方法也适合其他的Centos系统,下面介绍Red hat怎么永久修改主机名hostname的三种方法. 方法一: 说明"hostname" ...
- Android 4.0源码目录结构
转:http://blog.csdn.net/xiangjai/article/details/9012387 在学习Android的过程中,学习写应用还好,一开始不用管太多代码,直接调用函数就可以了 ...
- mac上安装gradle
首先,先download最新版本的gradle,网址如下:http://www.gradle.org/get-started然后将下载下来的zip包放在你要安装的路径上,我安装在/usr/local/ ...
- hdu 1011 树形dp
题意:是有n个洞组成一棵树,你有m个士兵,你从1号房间开始攻打,每个洞有a个"bugs"和b的价值.你的一个士兵可以打20 个"bugs",为了拿到这个洞的价值 ...
- 建模算法(十一)——目标规划
求解多目标规划的思路 1.加权系数法 为每一个目标加一个权系数,把多目标模型转化成单一目标模型.但是困难时确定合理的权系数,以反映不同目标之间的重要程度. 2.优先等级法 将各目标按其重要程度分为不同 ...
- java 输入输出流1 FileInputStrem&&FileOutStream
通过文件输入流读取问价 package unit6; import java.io.FileInputStream; import java.io.FileNotFoundException; imp ...