bzoj 2929 [Poi1999]洞穴攀行

LINK:洞穴攀行

题目有鬼了。。

注意理解时间的含义 并非同一时刻而是指某次训练。

所以可以发现是最大流。

//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define gc(a) scanf("%s",a+1)
#define rep(p,n,i) for(RE int i=p;i<=n;++i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE int i=n;i>=p;--i)
#define pii pair<int,int> 
#define mk make_pair
#define mod 998244353
#define RE register
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define ull unsigned long long
#define P 1000000000000000ll
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    RE int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=210;
int n,m,S,len=1,T,L,R,ans;
int cur[MAXN],vis[MAXN],q[MAXN*MAXN<<1];
int lin[MAXN],ver[MAXN*MAXN<<1],nex[MAXN*MAXN<<1],e[MAXN*MAXN<<1];
inline void add(int x,int y,int z)
{
    ver[++len]=y;nex[len]=lin[x];lin[x]=len;e[len]=z;
    ver[++len]=x;nex[len]=lin[y];lin[y]=len;e[len]=0;
}
inline int dinic(int x,int flow)
{
    if(x==T)return flow;
    int res=flow,k;
    for(int i=cur[x];i&&res;i=nex[i])
    {
        int tn=ver[i];cur[x]=i;
        if(vis[tn]==vis[x]+1&&e[i])
        {
            k=dinic(tn,min(e[i],res));
            if(!k){vis[tn]=0;continue;}
            e[i]-=k;e[i^1]+=k;res-=k;
        }
    }
    return flow-res;
}
inline int bfs()
{
    rep(1,T,i)vis[i]=0,cur[i]=lin[i];
    L=R=0;q[++R]=S;vis[S]=1;
    while(++L<=R)
    {
        int x=q[L];
        go(x)
        {
            if(vis[tn]||!e[i])continue;
            vis[tn]=vis[x]+1;
            q[++R]=tn;
            if(tn==T)return 1;
        }
    }
    return 0;
}
int main()
{
    //freopen("1.in","r",stdin);
    get(n);S=1;T=n;
    rep(1,n-1,i)
    {
        int get(x),y;
        rep(1,x,j)get(y),add(i,y,(i==1||y==n)?1:INF);
    }
    int flow,sum=0;
    while(bfs())while((flow=dinic(S,INF)))sum+=flow;
    put(sum);
    return 0;
}
posted @ 2020-04-07 10:47  chdy  阅读(115)  评论(0编辑  收藏  举报