# Bzoj2929 [poi1999]洞穴攀行

Posted by yjjr's blog on February 6, 2018 1 minutes to read

# 题目

Description

Output

Sample Input

12

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

3

# code

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define rep(i,a,b) for(register int i=a;i<=b;i++)
#define dep(i,a,b) for(register int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define inf 0x7fffffff
using namespace std;
{
ll f=1,x=0;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;
}
const int maxn=206;
struct edge{int to,next,v;}e[maxn*maxn];
int h[maxn],que[maxn],last[maxn],cnt=1,ans=0,n;
void insert(int u,int v,int w){
e[++cnt]=(edge){v,last[u],w};last[u]=cnt;
e[++cnt]=(edge){u,last[v],0};last[v]=cnt;
}

bool bfs()
{
mem(h,-1);
que[0]=1;h[1]=0;
#define reg(x) for(int i=last[x];i;i=e[i].next)
reg(now)
if(e[i].v&&h[e[i].to]==-1){
h[e[i].to]=h[now]+1;
que[tail++]=e[i].to;
}
}
if(h[n]==-1)return 0;else return 1;
}

int dfs(int x,int f)
{
if(x==n)return f;
int w,used=0;
reg(x)
if(e[i].v&&h[e[i].to]==h[x]+1){
w=f-used;w=dfs(e[i].to,min(e[i].v,w));
e[i].v-=w;e[i^1].v+=w;
used+=w;if(used==f)return f;
}
if(!used)h[x]=-1;
return used;
}
void dinic(){while(bfs())ans+=dfs(1,inf);}
int main()
{
rep(i,1,n-1){
while(m--){
if(i==1||x==n)insert(i,x,1);
else insert(i,x,inf);
}
}
dinic();
cout<<ans<<endl;
return 0;
}