bzoj2929 [Poi1999]洞穴攀行
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
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
#define S 1
#define T n
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,cnt=1,ans;
struct edge{
int to,next,v;
}e[1000010];
int head[200010];
int h[200010];
int q[200010];
inline void ins(int u,int v,int w)
{
e[++cnt].to=v;
e[cnt].v=w;
e[cnt].next=head[u];
head[u]=cnt;
}
inline void insert(int u,int v,int w)
{
ins(u,v,w);
ins(v,u,0);
}
inline bool bfs()
{
memset(h,-1,sizeof(h));
int t=0,w=1;
h[S]=0;q[1]=S;
while (t<w)
{
int now=q[++t];
for (int i=head[now];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==-1)
{
h[e[i].to]=h[now]+1;
q[++w]=e[i].to;
}
}
if (h[T]==-1)return 0;
return 1;
}
inline int dfs(int x,int f)
{
if (x==T||!f)return f;
int w,used=0;
for (int i=head[x];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==h[x]+1)
{
w=dfs(e[i].to,min(e[i].v,f-used));
e[i].v-=w;
e[i^1].v+=w;
used+=w;
if (used==f)return f;
}
if (!used)h[x]=-1;
return used;
}
inline void dinic()
{while(bfs())ans+=dfs(S,inf);}
int main()
{
n=read();
for (int i=1;i<n;i++)
{
int x=read();
for (int j=1;j<=x;j++)
{
int to=read();
if (i==1||to==n)insert(i,to,1);
else insert(i,to,inf);
}
}
dinic();
printf("%d\n",ans);
}
bzoj2929 [Poi1999]洞穴攀行的更多相关文章
- 【最大流】【Dinic】bzoj2929 [Poi1999]洞穴攀行
TMD 题意其实是与1或n相连的边只能走一次,其他可以走无限次……翻译去死. 裸最大流. #include<cstdio> #include<cstring> #include ...
- 2929: [Poi1999]洞穴攀行
2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 41[Submit][Status][Di ...
- 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][ ...
- 【bzoj2929】[Poi1999]洞穴攀行 网络流最大流
题目描述 洞穴学者在Byte Mountain的Grate Cave里组织了一次训练.训练中,每一位洞穴学者要从最高的一个室到达最底下的一个室.他们只能向下走.一条路上每一个连续的室都要比它的前一个低 ...
- 【BZOJ】2929: [Poi1999]洞穴攀行(最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=2929 题意描述不清..搞得我wa了一发.. 应该是,有1和n的点的边容量都为1,其余随便... 然后 ...
- BZOJ-2929 洞穴攀岩 最大流Dinic(傻逼题)
竟然没有1A真羞耻...1分钟不到读完题,10分钟不到打完....MD没仔细看...WA了一遍,贱! 2929: [Poi1999]洞穴攀行 Time Limit: 1 Sec Memory Limi ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- jquery轮播图详解,40行代码即可简单解决。
我在两个月以前没有接触过html,css,jquery,javascript.今天我却在这里分享一篇技术贴,可能在技术大牛面前我的文章漏洞百出,也请斧正. 可以看出来,无论是div+css布局还是jq ...
随机推荐
- Linux开关机命令详解
Linux系统的开关机主要涉及(shutdown,reboot,poweroff,halt,init)这几条命令,本文对其使用详解如下: 一.命令简介 shutdown,poweroff,reboot ...
- MyEclipse中用Maven创建Web项目(亲测有效)
new --> other 1.Wizards: mvaen 2.Maven Project 3.Next Use Default Workspace Location 1.weba ...
- C语言 · 数字三角形 · 算法训练
问题描述 (图3.1-1)示出了一个数字三角形. 请编一个程序计算从顶至底的某处的一条路 径,使该路径所经过的数字的总和最大. ●每一步可沿左斜线向下或右斜线向下走: ●1<三角形行数≤100: ...
- Django 内置分页--Paginator类
官方文档 http://python.usyiyi.cn/django/topics/pagination.html 前端方法 http://www.tuicool.com/articles/RniU ...
- PHP中字符串类型与数值类型混合计算
字符串转数值的规则 当一个字符串被当作一个数值来取值,其结果和类型如下: 如果该字符串没有包含 '.','e' 或 'E' 并且其数字值在整型的范围之内(由 PHP_INT_MAX 所定义),该字符串 ...
- Yum出错Error: Cannot find a valid baseurl for repo: base
centos yum 错误 Error: Cannot find a valid baseurl for repo: addons 装了个CentOS 6.5,使用yum时出现了以下的错误提示. [r ...
- [React] React Router: setRouteWillLeaveHook
setRouteWillLeaveHook provides a method for us to intercept a route change before leaving the curren ...
- [iOS]使用symbolicatecrash分析crash文件
对于我们iOS开发者来说,最心碎的事莫过于苹果审核一个星期后上架app store,而第二天就报出闪退bug.一周前我刚经历过,而且最坑的是由于第一次做个人开发,经验不足,没有集成友盟的分析SDK,还 ...
- Java基础知识强化61:经典查找之 常见查找算法小结
一.顺序查找 条件:无序或有序队列. 原理:按顺序比较每个元素,直到找到关键字为止. 时间复杂度:O(n) 二.二分查找(折半查找) 条件:有序数组 原理:查找过程从数组的中间元素开始,如果中间元素正 ...
- 网页JavaScript1
DOM的操作 windows对象操作 属性: opener,打开当前窗口的源窗口,首次启动 是null. dialogArgument,对话框的返回值 子对象: history , location ...