[bzoj2502]清理雪道[上下界网络流]
bzoj状态里有两种,一种时间是个位数,一种是四位数,我就是四位数的那种,,,估计都是看了hzwer..
#include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; template<const int _n,const int _m>
struct Edge
{
struct Edge_base { int to,next,w; }e[_m]; int cnt,p[_n];
Edge() { clear(); }
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 start(const int x) { return p[x]; }
void clear() { cnt=;memset(p,,sizeof(p)); }
void Link(const int x,const int y,const int z)
{ insert(x,y,z); insert(y,x,); }
Edge_base& operator[](const int x) { return e[x]; }
}; Edge<,>e;
int n,cnt,Flow,level[];
int SS,SSS,TTT,cur[],In[]; 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(e[i].w,rest));
e[i].w-=flow;
e[i^].w+=flow;
if((rest-=flow)<=)break;
}
}
if(bk==rest)level[S]=;
return bk-rest;
} void Dinic()
{
while(Bfs(SSS))
{
memcpy(cur,e.p,sizeof(cur));
Flow+=Dfs(SSS,INF);
}
return ;
} int main()
{
int i,j,t,y; scanf("%d",&n);
for(i=;i<=n;++i)
{
scanf("%d",&t);
for(j=;j<=t;++j)
{
scanf("%d",&y);
cnt++;
e.Link(i,n+(cnt<<)-,INF);
e.Link(n+(cnt<<),y,INF);
}
} SS=n+cnt+cnt+,SSS=SS+,TTT=SSS+; for(i=;i<=cnt;++i)
e.Link(n+i+i-,n+i+i,INF),In[n+i+i-]--,In[n+i+i]++; for(i=n+;i<=n+cnt+cnt;++i)
if(In[i]>)e.Link(SSS,i,In[i]);
else e.Link(i,TTT,-In[i]); for(i=;i<=n;++i)e.Link(SS,i,INF); i=;
while(Flow!=cnt)
{
e.Link(SSS,SS,);
Dinic();i++;
} printf("%d\n",i); return ;
}
[bzoj2502]清理雪道[上下界网络流]的更多相关文章
- P4843 清理雪道(上下界网络流)
P4843 清理雪道 上下界最小流 我们先搞一遍上下界可行流(转) 回忆上下界最大流的写法:在可行流的残量网络$s\ -\ t$上跑最大流,答案为可行流$+$残量网络的最大流 那么上下界最小流的写法呢 ...
- [BZOJ2502]清理雪道 有上下界网络流(最小流)
2502: 清理雪道 Time Limit: 10 Sec Memory Limit: 128 MB Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场 ...
- [BZOJ2502]清理雪道
[BZOJ2502]清理雪道 试题描述 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定 ...
- hdu 4940 Destroy Transportation system( 无源汇上下界网络流的可行流推断 )
题意:有n个点和m条有向边构成的网络.每条边有两个花费: d:毁坏这条边的花费 b:重建一条双向边的花费 寻找这样两个点集,使得点集s到点集t满足 毁坏全部S到T的路径的费用和 > 毁坏全部T到 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)
https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...
- 算法笔记--最大流和最小割 && 最小费用最大流 && 上下界网络流
最大流: 给定指定的一个有向图,其中有两个特殊的点源S(Sources)和汇T(Sinks),每条边有指定的容量(Capacity),求满足条件的从S到T的最大流(MaxFlow). 最小割: 割是网 ...
- POJ 2396 Budget(有源汇上下界网络流)
Description We are supposed to make a budget proposal for this multi-site competition. The budget pr ...
- HDU 4940 Destroy Transportation system(无源汇上下界网络流)
Problem Description Tom is a commander, his task is destroying his enemy’s transportation system. Le ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)
"Oh, There is a bipartite graph.""Make it Fantastic."X wants to check whether a ...
随机推荐
- CF 1016 C —— 思路
题目:http://codeforces.com/contest/1016/problem/C 一定是先蛇形走在回形走,所以预处理.暴力即可: 自己一开始写了一个,总是WA,又看了看TJ写法: 模仿一 ...
- Kernel trick----PRML读书笔记
Many linear parametric models can be re-cast into an equivalent 'dual representstion' in which the p ...
- 安科 OJ 1054 排队买票 (递归,排列组合)
时间限制:1 s 空间限制:128 M 题目描述 有M个小孩到公园玩,门票是1元.其中N个小孩带的钱为1元,K个小孩带的钱为2元.售票员没有零钱,问这些小孩共有多少种排队方法,使得售票员总能找得开零钱 ...
- JavaScript中.和[]有什么区别?
.与[]都可以用于读取或修改对象属性. <script> var myData={ name:"Adam", weather:"sunny", }; ...
- WP8开发常用解决方案收集
我其实不怎么做wp的东西.但是偶尔还是会用到, 但是wp8开发的资料确实难找.特开此贴,记录一些常见的解决方案 1.水平滑动动画(比如app首次使用说明就可以用这个做) http://www.cnbl ...
- 【洛谷2624_BZOJ1005】[HNOI2008] 明明的烦恼(Prufer序列_高精度_组合数学)
题目: 洛谷2624 分析: 本文中所有的 "树" 都是带标号的. 介绍一种把树变成一个序列的工具:Prufer 序列. 对于一棵 \(n\) 个结点的树,每次选出一个叶子(度数为 ...
- 【BZOJ2595_洛谷4294】[WC2008]游览计划(斯坦纳树_状压DP)
上个月写的题qwq--突然想写篇博客 题目: 洛谷4294 分析: 斯坦纳树模板题. 简单来说,斯坦纳树问题就是给定一张有边权(或点权)的无向图,要求选若干条边使图中一些选定的点连通(可以经过其他点) ...
- ACM_栈的压入、弹出序列
栈的压入.弹出序列 Time Limit: 2000/1000ms (Java/Others) Problem Description: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列 ...
- ACM_绝对值排序
Why Males And Females Apart? Time Limit: 2000/1000ms (Java/Others) Problem Description: In so many o ...
- ACM_无聊者序列(斐波那契数列大数取余(同余)+规律)
Problem Description: 瓜瓜在玩着由红色和蓝色的大理石做成的玻璃珠,他将n个玻璃珠从左到右排成一个序列叫做无聊者序列.一个非空的红色和蓝色玻璃珠组成的序列是一个无聊者序列.这个序列的 ...