[BZOJ2929][POI1999]洞穴攀行(网络流)
来源:互联网 发布:查看linux sftp软件 编辑:程序博客网 时间:2024/04/28 16:55
题目描述
传送门
题解
题意不明啊= =
1出发和到达n的边只能走一次,其余随意。
那么很裸的网络流。
代码
#include<iostream>#include<cstring>#include<cstdio>#include<queue>using namespace std;const int max_n=205;const int max_N=max_n+2;const int max_m=max_n*max_n;const int max_e=max_m*2;const int INF=1e9;int n,m,N,x;int tot,point[max_N],next[max_e],v[max_e],remain[max_e];int deep[max_N],num[max_N],last[max_N],cur[max_N];int maxflow;queue <int> q;inline void addedge(int x,int y,int cap){ ++tot; next[tot]=point[x]; point[x]=tot; v[tot]=y; remain[tot]=cap; ++tot; next[tot]=point[y]; point[y]=tot; v[tot]=x; remain[tot]=0;}inline void bfs(int t){ for (int i=1;i<=N;++i) deep[i]=N; deep[t]=0; for (int i=1;i<=N;++i) cur[i]=point[i]; while (!q.empty()) q.pop(); q.push(t); while (!q.empty()){ int now=q.front(); q.pop(); for (int i=point[now];i!=-1;i=next[i]) if (deep[v[i]]==N&&remain[i^1]){ deep[v[i]]=deep[now]+1; q.push(v[i]); } }}inline int addflow(int s,int t){ int now=t,ans=INF; while (now!=s){ ans=min(ans,remain[last[now]]); now=v[last[now]^1]; } now=t; while (now!=s){ remain[last[now]]-=ans; remain[last[now]^1]+=ans; now=v[last[now]^1]; } return ans;}inline void isap(int s,int t){ bfs(t); for (int i=1;i<=N;++i) ++num[deep[i]]; int now=s; while (deep[s]<N){ if (now==t){ maxflow+=addflow(s,t); now=s; } bool has_find=false; for (int i=cur[now];i!=-1;i=next[i]) if (deep[v[i]]+1==deep[now]&&remain[i]){ has_find=true; cur[now]=i; last[v[i]]=i; now=v[i]; break; } if (!has_find){ int minn=N-1; for (int i=point[now];i!=-1;i=next[i]) if (remain[i]) minn=min(minn,deep[v[i]]); if (!(--num[deep[now]])) break; num[deep[now]=minn+1]++; cur[now]=point[now]; if (now!=s) now=v[last[now]^1]; } }}int main(){ tot=-1; memset(point,-1,sizeof(point)); memset(next,-1,sizeof(next)); scanf("%d",&n); N=n+2; for (int i=1;i<n;++i){ scanf("%d",&m); for (int j=1;j<=m;++j){ scanf("%d",&x); if (i==1||x==n) addedge(1+i,1+x,1); else addedge(1+i,1+x,INF); } } addedge(1,2,INF); addedge(N-1,N,INF); isap(1,N); printf("%d\n",maxflow);}
0 0
- [BZOJ2929][POI1999]洞穴攀行(网络流)
- 【bzoj2929】[Poi1999]洞穴攀行 最大流
- 【bzoj2929】【poi1999】【洞穴攀行】【最大流】
- BZOJ2929 [Poi1999]洞穴攀行
- BZOJ2929洞穴攀行
- BZOJ 2929 Poi1999 洞穴攀行 最大流
- BZOJ 2929: [Poi1999]洞穴攀行 最大流
- BZOJ 2929:[Poi1999]洞穴攀行
- BZOJ 2929 洞穴攀行
- [BZOJ2936][POI1999] 降水(堆+bfs:floodfill)
- [BZOJ2927][Poi1999]多边形之战(博弈)
- (未做)洞穴逃生
- 【bzoj 2936】[Poi1999]降 水(floodfill算法(BFS))
- bzoj 2936: [Poi1999]降 水 (floodfill算法)
- BZOJ 2936 [Poi1999]降 水 (FloodFill)优先队列+BFS
- [POI1999] 位图
- 华为-洞穴逃生(OJ通过)
- [BZOJ2049][SDOI2008]Cave 洞穴勘测(LCT)
- 单例模式的并发访问
- 线程的优先级设定与礼让
- Hduoj1427 【数学】
- 超全面指南!从零开始教你打造网页设计中的极简风格
- shiro +springmvc+freemarker session问题处理 shiro无法记录登陆前页面问题
- [BZOJ2929][POI1999]洞穴攀行(网络流)
- 基础算法-归并排序
- 你真的了解iOS代理设计模式吗?
- 我发表的CSDN博客
- 线程的同步:采用同步代码块实现同步
- This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.
- sql语句
- Activity的启动模式
- HDU2037(贪心-。-)