题意:

  就是求最小割点

解析:

  正向一遍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(最小割点)的更多相关文章

  1. 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)

    Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...

  2. 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 ...

  3. HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)

    Destroying the bus stations                                                                          ...

  4. Destroying the bus stations

    Destroying the bus stations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1832   Acce ...

  5. hdu 2485 Destroying the bus stations 最小费用最大流

    题意: 最少需要几个点才能使得有向图中1->n的距离大于k. 分析: 删除某一点的以后,与它相连的所有边都不存在了,相当于点的容量为1.但是在网络流中我们只能直接限制边的容量.所以需要拆点来完成 ...

  6. HDU 2485 Destroying the bus stations (IDA*+ BFS)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意:给你n个点,m条相连的边,问你最少去掉几个点使从1到n最小路径>=k,其中不能去掉1, ...

  7. HDU 2485 Destroying the bus stations(费用流)

    http://acm.hdu.edu.cn/showproblem.php?pid=2485 题意: 现在要从起点1到终点n,途中有多个车站,每经过一个车站为1时间,现在要在k时间内到达终点,问至少要 ...

  8. HDU 2485 Destroying the bus stations

    2015 ACM / ICPC 北京站 热身赛 C题 #include<cstdio> #include<cstring> #include<cmath> #inc ...

  9. hdu 2485(最小费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2485 思路:题目的意思是删除最少的点使1,n的最短路大于k.将点转化为边,容量为1,费用为0,然后就是 ...

随机推荐

  1. itoa()函数和atoi()函数详解

    C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串. 以下是用itoa()函数将整数转换为字符串的一个例子:# include <stdio.h># i ...

  2. H5 30-CSS元素的显示模式

    30-CSS元素的显示模式 我是div 我是段落 我是标题 我是span 我是加粗 我是强调 <!DOCTYPE html><html lang="en"> ...

  3. Python并发编程

    进程 相关概念 进程 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本 ...

  4. 解决linux用户切换失败 su:execute /usr/bin 没有权限

    问题描述: 回宿舍前,在root用户中安装fish,并修改其shell为fish.回宿舍之后,在图形界面用root用户进行登陆,莫名其妙登陆失败.没有任何提示信息,直接回到登陆界面.用非root用户登 ...

  5. 【Python3练习题 005】输入三个整数x,y,z,请把这三个数由小到大输出

    import re x, y, z = re.split(',| |,| ', input('请输入3个数字,用逗号或空格隔开:'))x, y, z = int(x), int(y), int(z) ...

  6. IdentityServer4【Topic】之授权类型

    Grant Types 授权类型 授权类型指出了一个客户端如何与IdentityServer进行交互.OpenID Conect和OAuth2.0定义了如下的授权类型: Implicit Author ...

  7. array_column函数

    <?php $arr = [ [ 'id'=>1, 'name'=>'wang', 'age'=>10 ], [ 'id'=>2, 'name'=>'yong', ...

  8. 一条SQL语句执行得很慢的原因有哪些?(转)

    一条 SQL 语句执行的很慢,那是每次执行都很慢呢?还是大多数情况下是正常的,偶尔出现很慢呢?所以我觉得,我们还得分以下两种情况来讨论. 1.大多数情况是正常的,只是偶尔会出现很慢的情况. 2.在数据 ...

  9. 理解根目录,classpath, getClass().getResourceAsStream和getClass().getClassLoader().getResourceAsStream的区别

    一: 理解根目录 <value>classpath*:/application.properties</value> <value>classpath:/appli ...

  10. Redis事物

    redis事物定义: >Redis事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的命令请求所打断. >Redis事务的主要作 ...