Destroying the bus stations HDU - 2485(最小割点)
题意:
就是求最小割点
解析:
正向一遍spfa 反向一遍spfa 然后遍历每一条边,对于当前边 如果dis1[u] + dis2[v] + 1 <= k 那么就把这条边加入到网络流图中,
每个点拆点 边权为1
跑最大流即可
代码还是改的那一题。。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn = 1e3 + , INF = 0xfffffff, maxm = ;
typedef long long LL;
int n,m, cnt, s, t, k;
int head[maxn], d[maxn], vis[maxn], dis1[maxn], dis2[maxn], head1[maxn], cur[maxn];
int from[maxm], to[maxm];
int bz[][], way[][]; struct edge
{
int u, v, c, next;
}Edge[maxm << ]; void add_(int u, int v, int c)
{
Edge[cnt].u = u;
Edge[cnt].v = v;
Edge[cnt].c = c;
Edge[cnt].next = head1[u];
head1[u] = cnt++;
} void add_edge(int u, int v, int c)
{
add_(u, v, c);
add_(v, u, );
} bool bfs()
{
mem(d, );
queue<int> Q;
Q.push(s);
d[s] = ;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int i = head1[u]; i != -; i = Edge[i].next)
{
edge e = Edge[i];
if(!d[e.v] && e.c > )
{
d[e.v] = d[u] + ;
Q.push(e.v);
if(e.v == t) return ;
}
}
}
return d[t] != ;
} int dfs(int u, int cap)
{
int ret = ;
if(u == t || cap == )
return cap;
for(int &i = cur[u]; i != -; i = Edge[i].next)
{
edge e = Edge[i];
if(d[e.v] == d[u] + && e.c > )
{
int V = dfs(e.v, min(e.c, cap));
Edge[i].c -= V;
Edge[i ^ ].c += V;
ret += V;
cap -= V;
if(cap == ) break;
}
}
if(cap > ) d[u] = -;
return ret;
} int Dinic()
{
int ans = ;
while(bfs())
{
memcpy(cur, head1, sizeof(head1));
ans += dfs(s, INF);
}
return ans;
} struct node
{
int u, v, w, next;
}Node[maxn * ]; void add(int u,int v,int w,int i)
{
Node[i].u = u;
Node[i].v = v;
Node[i].w = w;
Node[i].next = head[u];
head[u] = i;
}
void spfa(int s)
{
for(int i = ; i < maxn; i++) d[i] = INF;
queue<int> Q;
d[s] = ;
mem(vis,);
Q.push(s);
vis[s] = ;
while(!Q.empty())
{
int u = Q.front();Q.pop();
vis[u] = ;
for(int i=head[u]; i!=-; i=Node[i].next)
{
node e = Node[i];
if(d[e.v] > d[u] + e.w)
{
d[e.v] = d[u] + e.w;
if(!vis[e.v])
{
Q.push(e.v);
vis[e.v] = ;
}
}
} }
} int main()
{
int T,A,B;
while(~scanf("%d%d%d", &n, &m, &k))
{
if(n==&&m==&&k==)
break;
mem(way, );
mem(bz, );
mem(Node,);
mem(head,-);
mem(head1, -);
cnt = ;
for(int i=; i<m; i++)
{
scanf("%d%d",&from[i],&to[i]);
if(!bz[from[i]][to[i]])
{
add(from[i],to[i],,i), bz[from[i]][to[i]] = ;
way[from[i]][to[i]] = ;
}
}
s = , t = n;
spfa(s);
mem(Node,);
for(int i=; i<=n; i++)
dis1[i] = d[i];
mem(head,-);
for(int i=; i<m; i++)
add(to[i],from[i],,i);
spfa(t);
for(int i=; i<=n; i++)
dis2[i] = d[i];
mem(bz, );
s = + n, t = n;
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
if(way[i][j] && dis1[i] + dis2[j] + <= k)
add_edge(i, j, INF);
}
add_edge(i, i + n, );
} printf("%d\n",Dinic());
}
return ;
}
Destroying the bus stations HDU - 2485(最小割点)的更多相关文章
- 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)
Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...
- HDU 2485 Destroying the bus stations(!最大流∩!费用流∩搜索)
Description Gabiluso is one of the greatest spies in his country. Now he’s trying to complete an “im ...
- HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)
Destroying the bus stations ...
- Destroying the bus stations
Destroying the bus stations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1832 Acce ...
- hdu 2485 Destroying the bus stations 最小费用最大流
题意: 最少需要几个点才能使得有向图中1->n的距离大于k. 分析: 删除某一点的以后,与它相连的所有边都不存在了,相当于点的容量为1.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...
- HDU 2485 Destroying the bus stations (IDA*+ BFS)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意:给你n个点,m条相连的边,问你最少去掉几个点使从1到n最小路径>=k,其中不能去掉1, ...
- HDU 2485 Destroying the bus stations(费用流)
http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意: 现在要从起点1到终点n,途中有多个车站,每经过一个车站为1时间,现在要在k时间内到达终点,问至少要 ...
- HDU 2485 Destroying the bus stations
2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...
- hdu 2485(最小费用最大流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2485 思路:题目的意思是删除最少的点使1,n的最短路大于k.将点转化为边,容量为1,费用为0,然后就是 ...
随机推荐
- PV、UV、IP、TPS、QPS、RPS、两天、吞吐量、 并发用户数 术语
跟网站打交道,经常可以听到数据分析之类的专有名词,如pv多少.ip多少.tps多少之类的问题.下面就这些常见的数据给出其释义. PV 即 page view,页面浏览量 用户每一次 ...
- H5 id选择器和class选择器
11-id选择器和class选择器 第一段文字 第二段文字 第三段文字 --> 第一段文字 第二段文字 第三段文字 <!DOCTYPE html> <html lang=&qu ...
- 使用C# HttpWebRequest进行多线程网页提交。Async httpclient/HttpWebRequest实现批量任务的发布及异步提交和超时取消
使用线程池并发处理request请求及错误重试,使用委托处理UI界面输出. http://www.cnblogs.com/Charltsing/p/httpwebrequest.html for (i ...
- Problem 2285 迷宫寻宝
http://acm.fzu.edu.cn/problem.php?pid=2285 Problem Description 洪尼玛今天准备去寻宝,在一个n*n (n行, n列)的迷宫中,存在着一个入 ...
- 项目管理、软件、禅道 VS JIRA
项目管理软件之争,禅道和JIRA大对比 - 简书https://www.jianshu.com/p/2533c0b7e456 [原创]项目管理软件之争,禅道和JIRA大对比 - zhengqiaoyi ...
- web安全测试排查
漏洞排查思路: 1.上传漏洞 如果看到:选择你要上传的文件 [重新上传]或者出现“请登陆后使用”,80%就有漏洞了! 有时上传不一定会成功,这是因为Cookies不一样.我们就要用WSockExper ...
- b,B,KB,MB,GB,TB,PB,EB,ZB,YB,BB,NB,DB的含义,之间的关系
1bit=1位2进制信息 1B (byte 字节)1KB(Kilobyte 千字节)=2(10)B=1024B=2(10)B: 1MB(Megabyte 兆字节)=2(10)KB=1024KB=2(2 ...
- Error Boundaries 错误边界
错误边界是用于捕获其子组件树 JavaScript 异常,记录错误并展示一个回退的 UI 的 React 组件,而不是整个组件树的异常.错误边界在渲染期间.生命周期方法内.以及整个组件树构造函数内捕获 ...
- SQL server 生成数据字典
Set nocount on ), ) DECLARE Tbls CURSOR FOR ),isnull(g.[value],'-')) AS TABLE_COMMENT FROM INFORMATI ...
- Chrome 浏览器的简单设置 无痕模式 暗黑模式 自定义用户目录
1. Chrome73 新增加了暗黑模式 可以通过修改快捷方式的方式来默认开启方法如下 1.1 关闭浏览器 2.2 鼠标焦点定位到任务栏 Chrome 图标处, 并且按住shift 按键 执行右键操作 ...