将一个空间站分为天数个点,每次枚举天数,每增加一天就把对应天数的边连上,用网络流判定可行性,即-判断最大流是否不小于k,注意编号不要错位。通过此题,可见一些网络流题目需要用到网络判定方法,但虽然答案具有单调性,却不适合二份答案,原因有两个:一是网络流题目一般数据规模不会很大,二是网络流题目如果二分就必须每次全部重新建图,而普通枚举可以在上以阶段的图中递推操作,所以往往枚举的效率和代码复杂度更好。

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <queue> using namespace std; #define INF 0x3f3f3f3f template<const int _n>
struct Edge
{
struct Edge_base { int to,w,next; }e[_n];
int cnt,p[_n];
Edge() { clear(); }
void clear() { cnt=,memset(p,,sizeof(p)); }
int start(const int x) { return p[x]; }
Edge_base& operator[](const int x) { return e[x]; }
void insert(const int x,const int y,const int z)
{ e[++cnt].to=y; e[cnt].next=p[x]; e[cnt].w=z; p[x]=cnt; return ; }
}; int n,m,SSS,TTT,Flow;
int level[],cur[],h[];
vector<int> vec[];
Edge<> e; bool Bfs(const int S)
{
int i,t;
queue<int> Q;
memset(level,,sizeof(level));
level[S]=;
Q.push(S);
while(!Q.empty())
{
t=Q.front(),Q.pop();
for(i=e.start(t);i;i=e[i].next)
{
if(!level[e[i].to] && e[i].w)
{
level[e[i].to]=level[t]+;
Q.push(e[i].to);
}
}
}
return level[TTT];
} int Dfs(const int S,const int bk)
{
if(S==TTT)return bk;
int rest=bk;
for(int &i=cur[S];i;i=e[i].next)
{
if(level[e[i].to]==level[S]+ && e[i].w)
{
int flow=Dfs(e[i].to,min(rest,e[i].w));
e[i].w-=flow;
e[i^].w+=flow;
if((rest-=flow)<=)break;
}
}
if(rest==bk)level[S]=;
return bk-rest;
} int Dinic()
{
while(Bfs(SSS))
{
memcpy(cur,e.p,sizeof(cur));
Flow+=Dfs(SSS,0x3f3f3f3f);
}
return Flow;
} int P(const int x,const int y)
{
return y*n+x;
} int main()
{
freopen("home.in","r",stdin);
freopen("home.out","w",stdout);
int i,j,t,k,c; scanf("%d%d%d",&n,&m,&k);
for(i=;i<=m;++i)
{
scanf("%d%d",&h[i],&t);
for(j=;j<=t;++j)
{
scanf("%d",&c);
if(c==-)c=n+;if(c==)c=n+;
vec[i].push_back(c);
if(j!=)e.insert(vec[i][j-],vec[i][j-],);
}
e.insert(vec[i][t-],vec[i][],i);
} SSS=n+,TTT=n+;
n+=;
int S=n,T=n-;
if(!Bfs(SSS)){printf("0\n");goto End;} e.clear();SSS=,TTT=SSS+;
e.insert(SSS,P(S,),INF);e.insert(P(S,),SSS,);
e.insert(P(T,),TTT,INF);e.insert(TTT,P(T,),);
for(i=;;i++)
{
e.insert(SSS,P(S,i),INF);
e.insert(P(S,i),SSS,);
e.insert(P(T,i),TTT,INF);
e.insert(TTT,P(T,i),);
for(j=;j<=n;++j)
{
e.insert(P(j,i-),P(j,i),INF);
e.insert(P(j,i),P(j,i-),);
}
for(j=;j<=m;++j)
{
e.insert(P(vec[j][(i-)%vec[j].size()],i-),P(vec[j][i%vec[j].size()],i),h[j]);
e.insert(P(vec[j][i%vec[j].size()],i),P(vec[j][(i-)%vec[j].size()],i-),);
}
if(Dinic()>=k)break;
} printf("%d\n",i); End:
return ;
}

最新文章

  1. jmeter(九)逻辑控制器
  2. [转载]python gevent
  3. php配置
  4. Educational Codeforces Round 10
  5. SQL Server进制
  6. 1069 Nim游戏
  7. Connectify是一款很实用的免费软件。能把计算机变成一个无线路由器
  8. OC2_数组操作
  9. Selenium webdriver firefox 路径设置问题
  10. 前端的数据库:IndexedDB 。 ps:入门
  11. webstorm for mac 破解步骤
  12. C#学习单向链表和接口 IList&lt;T&gt;
  13. webService接口交互
  14. solr-geohsah 按照距离搜索分组
  15. UWP TextBox私人定制
  16. springboot~maven制作底层公用库
  17. datetime库运用
  18. 调用微信的扫一扫功能详解说明---(java 排坑版)
  19. 分布式监控系统Zabbix-批量添加聚合图形
  20. BZOJ3786星系探索——非旋转treap(平衡树动态维护dfs序)

热门文章

  1. bag of words in c++
  2. putty+Xmanager登陆Linux,实现图形界面操作.
  3. U盘在电脑上安装CentOS 7 系统过程详解
  4. WCF 通讯标准绑定
  5. 《Akka应用模式:分布式应用程序设计实践指南》读书笔记9
  6. 服务器端 CentOS 下配置 JDK 和 Tonmcat 踩坑合集
  7. DetachedCriteria和Criteria的使用方法
  8. Java_Web三大框架之Hibernate+HQL语言基础
  9. RHEL7配置中文输入法-智能拼音
  10. 论文deadline 最后三天