题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2485

题目要求:删除最少的点,使得源点到汇点的距离大于k

思路:拆点、建图求费用小于等于k的最大流

#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <queue>
using namespace std;
#define min(x,y) (x)<(y)?(x):(y)
const int maxm = 10005;
const int maxn = 1100; struct node{
int v,flow,cost,next;
}edge[maxm];
int head[maxn],dis[maxn],vis[maxn],pre[maxn],cur[maxn];
int id,n,m,k;
int sink,source;
void add_edge(int u,int v,int flow,int cost){
edge[id].v = v;edge[id].cost = cost;edge[id].flow = flow;edge[id].next = head[u];head[u] = id++;
edge[id].v = u;edge[id].cost = -cost;edge[id].flow = 0 ;edge[id].next = head[v];head[v] = id++;
}
void init(){
int u,v,i;
source = 1,sink = n*2;
memset(head,-1,sizeof(head));id = 0;
for( i = 1; i <= m; i++){
scanf("%d%d",&u,&v);
add_edge(u+n,v,1,1);
}
for( i = 2; i < n; i++)//拆点
add_edge(i,i+n,1,0);
add_edge(1,n+1,5000000,0);
add_edge(n,n+n,5000000,0);
} int spfa(){
memset(dis,-1,sizeof(dis));
memset(vis,0,sizeof(vis));
pre[source] = source;
dis[source] = 0;
vis[source] = 1;
queue<int>que;
que.push(source);
while( !que.empty()){
int u = que.front();
que.pop();
vis[u] = 0;
for(int id = head[u]; id != -1; id = edge[id].next){
int v = edge[id].v;
if(edge[id].flow > 0 && (dis[v] == -1 || dis[v] > dis[u] + edge[id].cost )){
dis[v] = dis[u] + edge[id].cost;
pre[v] = u;cur[v] = id;
if(!vis[v] ){
vis[v] = 1;
que.push(v);
}
}
}
}
if(dis[sink] == -1 || dis[sink] > k)return 0;
return 1;
} int get_max(){
int max_flow = 0;
while(spfa())
{
//cout << dis[sink] << endl;
max_flow += 1;
int now = sink;
while(now != source){
edge[cur[now]].flow -= 1;
edge[cur[now]^1].flow += 1;
now = pre[now];
}
}
return max_flow;
}
int main(){
freopen("in.txt","r",stdin);
while(~scanf("%d%d%d",&n,&m,&k),n||m||k){
init();
printf("%d\n",get_max());
}
return 0;
}

  

HDU2485Destroying the bus stations 拆点网络流求割点个数的更多相关文章

  1. POJ1144Network(求割点个数)

    题目链接 题意:一共n割点,然后若干行,每行第一个输入一个点,然后若干个点表示与他相连,0单独一行表示一个样例的结束.然后求图中的割点个数 割点:去掉该点之后得到的图不在连通,那么该店就是割点 一般割 ...

  2. loj 1063(求割点个数)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26780 思路:判断一个点是否是割点的两个条件:1.如果一个点v是根 ...

  3. POJ 1144 Network(tarjan 求割点个数)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17016   Accepted: 7635 Descript ...

  4. Destroying the bus stations HDU - 2485(最小割点)

    题意: 就是求最小割点 解析: 正向一遍spfa 反向一遍spfa  然后遍历每一条边,对于当前边 如果dis1[u] + dis2[v] + 1 <= k 那么就把这条边加入到网络流图中, 每 ...

  5. UVA 315 315 - Network(求割点个数)

     Network  A Telephone Line Company (TLC) is establishing a new telephone cable network. They are con ...

  6. UVA-315 无向图求割点个数

    题意抽象: 给定一个无向图,输出割点个数. 割点定义:删除该点后,原图变为多个连通块. 考虑一下怎么利用tarjan判定割点: 对于点u和他相连的当时还未搜到的点v,dfs后如果DFN[u]<= ...

  7. poj 1144(求割点个数)

    题目链接:http://poj.org/problem?id=1144 思路:判断一个点是否是割点的两个条件:1.如果一个点v是根结点并且它的子女个数大于等于2,则v是割点.2.如果点v不是根结点,并 ...

  8. poj1144 Network【tarjan求割点】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html   ---by 墨染之樱花 [题目链接]http://poj.org/p ...

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

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

随机推荐

  1. JS 自执行函数

    由于自己js基础知识薄弱,很多js的知识还没有掌握,所以接下来会经常写一些关于js基础知识的博客,也算给自己提个醒吧. js自执行函数,听到这个名字,首先会联想到函数.接下来,我来定义一个函数: fu ...

  2. Extjs4 combobox autoLoad: true 时,加载两次

    问题是这样的,combobox 远程加载数据时,当我们把 store 设置为  autoLoad: tue, 时,这样页面加载时,store 会load 一次,但是我们在第一次点击 下来框时,他还会 ...

  3. WEB基础(一)--JSP的9个内置对象

    1.request request 对象是 javax.servlet.httpServletRequest类型的对象. 该对象代表了客户端的请求信息,主要用于接受通过HTTP协议传送到服务器的数据. ...

  4. 新手的java学习建议

    前言 进入IT领域,就像进入大海—浩瀚而广阔.然而,它又很容易让人迷茫,不知所措.所以,在IT的海洋中,找好一艘船特别重要,这艘船带你前进.减少迷失.这艘船或许是一个人,或一本书,又或许是一篇文章. ...

  5. 【Kubernetes 系列二】从虚拟机讲到 Kubernetes 架构

    目录 什么是虚拟机? 什么是容器? Docker Kubernetes 架构 Kubernetes 对象 基础设施抽象 在认识 Kubernetes 之前,我们需了解下容器,在了解容器之前,我们得先知 ...

  6. win7-BIOS中开启AHCI模式电脑蓝屏怎么办?

    win7-BIOS中开启AHCI模式电脑蓝屏怎么办? 来源:U大师 u盘装系统 不少网友都表示给电脑安装win7系统后,如果在BIOS中开启IDE模式就一切正常而为AHCI模式时就会出现蓝屏.其实那是 ...

  7. android ——活动

    活动(Activity)主要用于和用户进行交互,是一种可以包含用户界面的组件. 1.手动创建活动 右击com.example.administrator.exp5→New→Activity→Empty ...

  8. c语言ld returned 1 exit status😂

    在复习c语言过程中遇到, 问题:reverseLinkedList.exe: Permission denied collect2.exe: error: ld returned 1 exit sta ...

  9. React 练习项目,仿简书博客写作平台

    Introduction 技术栈:react + redux + react-router + express + Nginx 练习点: redux 连接 react-router 路由跳转 scss ...

  10. (六)c#Winform自定义控件-单选框

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...