链接:

https://vjudge.net/problem/UVA-10480

题意:

The regime of a small but wealthy dictatorship has been abruptly overthrown by an unexpected rebellion. Because of the enormous disturbances this is causing in world economy, an imperialist military

super power has decided to invade the country and reinstall the old regime.

For this operation to be successful, communication between the capital and the largest city must

be completely cut. This is a difficult task, since all cities in the country are connected by a computer

network using the Internet Protocol, which allows messages to take any path through the network.

Because of this, the network must be completely split in two parts, with the capital in one part and

the largest city in the other, and with no connections between the parts.

There are large differences in the costs of sabotaging different connections, since some are much

more easy to get to than others.

Write a program that, given a network specification and the costs of sabotaging each connection,

determines which connections to cut in order to separate the capital and the largest city to the lowest

possible cost.

思路:

求最少花费不联通,最小割,不过打印路径是最小割的一条边,不是全部边.

所有在最后一次增广后,bfs可以得到跟源点联通和跟汇点联通的边,打印对应的即可.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 200+10;
const int INF = 1e9; struct Edge
{
int from, to, cap;
};
vector<Edge> edges;
vector<int> G[MAXN*4];
int Dis[MAXN*4];
int a[MAXN*4], b[MAXN*4];
int n, m, s, t; void AddEdge(int from, int to, int cap)
{
edges.push_back(Edge{from, to, cap});
edges.push_back(Edge{to, from, cap});
G[from].push_back(edges.size()-2);
G[to].push_back(edges.size()-1);
} bool Bfs()
{
memset(Dis, -1, sizeof(Dis));
queue<int> que;
que.push(s);
Dis[s] = 0;
while (!que.empty())
{
int u = que.front();
que.pop();
// cout << u << endl;
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]];
if (e.cap > 0 && Dis[e.to] == -1)
{
Dis[e.to] = Dis[u]+1;
que.push(e.to);
}
}
}
return Dis[t] != -1;
} int Dfs(int u, int flow)
{
if (u == t)
return flow;
int res = 0;
for (int i = 0;i < G[u].size();i++)
{
Edge &e = edges[G[u][i]];
if (e.cap > 0 && Dis[u]+1 == Dis[e.to])
{
int tmp = Dfs(e.to, min(flow, e.cap));
// cout << "flow:" << e.from << ' ' << e.to << ' ' << tmp << endl;
e.cap -= tmp;
flow -= tmp;
edges[G[u][i]^1].cap += tmp;
res += tmp;
if (flow == 0)
break;
}
}
if (res == 0)
Dis[u] = -1;
return res;
} int MaxFlow()
{
int res = 0;
while (Bfs())
{
res += Dfs(s, INF);
}
return res;
} int main()
{
// freopen("test.in", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n >> m && n)
{
for (int i = 1;i <= n;i++)
G[i].clear();
edges.clear();
s = 1, t = 2;
int u, v, w;
for (int i = 1;i <= m;i++)
{
cin >> u >> v >> w;
AddEdge(u, v, w);
a[i] = u, b[i] = v;
}
int res = MaxFlow();
for (int i = 1;i <= m;i++)
{
if ((Dis[a[i]] >= 0 && Dis[b[i]] == -1) || (Dis[b[i]] >= 0 && Dis[a[i]] == -1))
cout << a[i] << ' ' << b[i] << endl;
}
cout << endl;
} return 0;
}

UVA-10480-Sabotage(最大流最小割,打印路径)的更多相关文章

  1. UVA 10480 Sabotage (最大流最小割)

    题目链接:点击打开链接 题意:把一个图分成两部分,要把点1和点2分开.隔断每条边都有一个花费,求最小花费的情况下,应该切断那些边. 这题很明显是最小割,也就是最大流.把1当成源点,2当成汇点. 问题是 ...

  2. UVA - 10480 Sabotage 最小割,输出割法

    UVA - 10480 Sabotage 题意:现在有n个城市,m条路,现在要把整个图分成2部分,编号1,2的城市分成在一部分中,拆开每条路都需要花费,现在问达成目标的花费最少要隔开那几条路. 题解: ...

  3. UVA 10480 Sabotage (网络流,最大流,最小割)

    UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...

  4. UVA 1626 区间dp、打印路径

    uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if( ...

  5. UVA 624 (0 1背包 + 打印路径)

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #i ...

  6. UVA 531 - Compromise(dp + LCS打印路径)

      Compromise  In a few months the European Currency Union will become a reality. However, to join th ...

  7. 紫书 例题 11-12 UVa 1515 (最大流最小割)

    这道题要分隔草和洞, 然后刘汝佳就想到了"割"(不知道他怎么想的, 反正我没想到) 然后就按照这个思路走, 网络流建模然后求最大流最小割. 分成两部分, S和草连, 洞和T连 外围 ...

  8. UVA - 10480 Sabotage【最小割最大流定理】

    题意: 把一个图分成两部分,要把点1和点2分开.隔断每条边都有一个花费,求最小花费的情况下,应该切断那些边.这题很明显是最小割,也就是最大流.把1当成源点,2当成汇点,问题是要求最小割应该隔断那条边. ...

  9. UVA 10480 Sabotage (最大流) 最小割边

    题目 题意: 编写一个程序,给定一个网络规范和破坏每个连接的成本,确定要切断哪个连接,以便将首都和最大的城市分离到尽可能低的成本. 分割-------------------------------- ...

随机推荐

  1. Linux 串口调试工具汇总

    minicomminicom 是一款启动速度快,功能强大的串口终端调试工具,当然缺点就是纯字符界面,没有图形界面的调试工具看起来直观方便,但是它功能十分强大,并且在一些没有屏幕的嵌入式主板上运行颇有用 ...

  2. 【HANA系列】SAP HANA 2.0 SPS00 SDA(Smart Data Access)连接Hadoop

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA 2.0 SPS ...

  3. 【HANA系列】SAP HANA计算视图中的RANK使用方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA计算视图中的RA ...

  4. 一本值得你反复研读的Python佳作《Python编程从0到1》

    现在的Python入门书太多太多了,究竟如何选择呢? 当然选最好的最入门的讲解最清晰的,没有那么多废话的. 现在就推荐一本<Python编程从0到1>,还带视频的,到时候跟大家一起学习沟通 ...

  5. JavaScript Array Reduce用于数组求和

    需求一 假设有一个数组,需要对其中的元素进行求和. const numbers = [1, -1, 2, 3]; 传统写法,使用for循环求和 const numbers = [1, -1, 2, 3 ...

  6. Java中的模板设计模式,太实用了!

    顾名思义,模板设计模式就是将许多公用的常用的代码封装成一个模板,我们只需要实现不同的业务需求的代码,然后和模板组合在一起,那么就得到完整的逻辑. 在我们的日常开发中,常用的模板模式有两种实现方式:继承 ...

  7. [codeforces1234F]Yet Another Substring Reverse

    题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长.只能翻转一次或零次. 设一个子串的状态为包含字符的二进制.如子串为$abacd$,则状态为$00000000000000 ...

  8. 初步学习jquery学习笔记(一)

    什么是jquery? Jquery是javascript的一个函数库包含以下功能: html元素选取 html元素的操作 css操作 html事件的函数 javacript的特效 html的遍历和修改 ...

  9. pair常见用法

    pair的使用 关于pair 什么是pair 可以将pair看做一个内部有两个元素的结构体,且两个元素的类型是可以指定的. struct pair{ typename1 first; typename ...

  10. 如何获取设置display:none元素及子元素的宽高

    由于元素设置了display:none时,页面便不会对其渲染,导致无法获取其元素的宽高.目前一般的做法都是先对其设置display:block,拿到数据再设置其为display:none.如此便可以了 ...