双倍经验题:HDU 6214,3987

求最小割的最小边。

方案一:

首先跑最大流,这个时候割上都满载了,于是将满载的边 cap = 1,其他 inf ,再跑最大流,这个时候限定这个网络的关键边就是那个最少边的那个割。

方案二:

奇技淫巧,将每条边 cap* A + 1,最大流 = flow / A ,最小割边 = fow % A;

原理:每条边容量扩大 到 cap * A + 1,那么最大流也一定扩大到 *A + 1,原图是多解,但是新图,

例如最少边的个是2条边,那么他就扩大到了 *A + 2,其他的就更大,那么就变成唯一解了。

#include <bits/stdc++.h>

using namespace std;

const int maxn = ;
const long long INF = 0x3f3f3f3f3f3f3f3f; struct Edge
{
int from,to;
long long cap,flow;
}; struct Dinic
{
int n,m,s,t;
vector<Edge> edge;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn]; void init()
{
for(int i=;i<maxn;i++)
G[i].clear();
edge.clear();
} void AddEdge (int from,int to,long long cap)
{
edge.push_back((Edge){from,to,cap,});
edge.push_back((Edge){to,from,,});
m = edge.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BFS()
{
memset(vis,,sizeof(vis));
queue<int> Q;
Q.push(s);
d[s] = ;
vis[s] = ;
while(!Q.empty())
{
int x = Q.front();
Q.pop();
for(int i=; i<(int)G[x].size(); i++)
{
Edge & e = edge[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to] = ;
d[e.to] = d[x] + ;
Q.push(e.to);
}
}
}
return vis[t];
} long long DFS(int x,long long a)
{
if(x==t||a==) return a;
long long flow = ,f;
for(int & i = cur[x]; i<(int)G[x].size(); i++)
{
Edge & e = edge[G[x][i]];
if(d[x] + ==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>)
{
e.flow +=f;
edge[G[x][i]^].flow -=f;
flow +=f;
a-=f;
if(a==) break;
}
}
return flow;
} long long Maxflow (int s,int t) {
this->s = s;this->t = t;
long long flow = ;
while(BFS()) {
memset(cur,,sizeof(cur));
flow+=DFS(s,INF);
}
return flow;
}
}sol; int main()
{
int T;
scanf("%d",&T); for(int z = ; z <= T; z++) {
int n,m;
scanf("%d%d",&n,&m);
int s,t;
scanf("%d%d",&s,&t);
s--;
t--;
sol.init();
for(int i = ; i < m; i++) {
int u,v; long long c;
scanf("%d%d%I64d",&u,&v,&c);
u--;
v--;
sol.AddEdge(u,v,c*+);
} printf("%lld\n",sol.Maxflow(s,t)%);
} return ;
}

HDU 6214 最小割边的更多相关文章

  1. HDU - 6214:Smallest Minimum Cut(最小割边最小割)

    Consider a network G=(V,E) G=(V,E) with source s s and sink t t . An s-t cut is a partition of nodes ...

  2. HDU 6214.Smallest Minimum Cut 最少边数最小割

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  3. hdu 6214 Smallest Minimum Cut[最大流]

    hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...

  4. HDU 6214 Smallest Minimum Cut 最小割,权值编码

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...

  5. HDU 6214 Smallest Minimum Cut(最少边最小割)

    Problem Description Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition o ...

  6. Smallest Minimum Cut HDU - 6214(最小割集)

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  7. HDU 6214 Smallest Minimum Cut (最小割且边数最少)

    题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...

  8. HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】

    Problem Description Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition ...

  9. hdu 6214 Smallest Minimum Cut(最小割的最少边数)

    题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...

随机推荐

  1. vi命令——修改文件内容

    以下内容转载自http://blog.csdn.net/bruce0532/article/details/7842384 vi编辑器是所有Unix及Linux系统下标准的编辑器,介绍一下它的用法和一 ...

  2. Python+Selenium操作select下拉框

    首先需要倒入Select模块: from selenium.webdriver.support.select import Select 常用方法: 通过索引定位:select_by_index() ...

  3. linux运维基础之系统挂载与etc文件下介绍

    1) 目录结构说明: windows:磁盘----分区---格式化--系统 linux:磁盘--分区--生成一个文件(磁盘分区) linux 中一切皆文件 ll -h 显示人类能看懂的 mount - ...

  4. Unity 判断Animatior是否播放完

    public Animator animator; void Start() { animator = this.GetComponent<Animator>(); } void Upda ...

  5. flex buider 4.6 打开设计模式(designer)时提示内存不足错误的解决办法

    先申明,此方法只适用于flex builder 4.6及以下版本, flex builder 4.7以后已经完全取消了designer功能,是没有办法补救的. 1. 首先下载APE文件,这个文件好像是 ...

  6. c# xml API操作

    LoginInfo loginInfo = new LoginInfo(); xmlNode = _xml.SelectSingleNode(loginUrl); loginInfo.LoginUrl ...

  7. ThenJS

    安装ThenJs:  npm i thenjs 史上最快,与 node callback 完美结合的异步流程控制库 <!doctype html> <html lang=" ...

  8. [LeetCode]20. Valid Parentheses有效的括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  9. C++里将string类字符串(utf-8编码)分解成单个字(可中英混输)

    最近在建词典,使用Trie字典树,需要把字符串分解成单个字.由于传入的字符串中可能包含中文或者英文,它们的字节数并不相同.一开始天真地认为中文就是两个字节,于是很happy地直接判断当前位置的字符的A ...

  10. 堆(Heap)的实现

    这次实现了堆,这个堆不是指系统堆栈的堆,是一种数据结构,见下图 堆的本质就是一个数组(上图中,红色的是值,黑色的是下标)简单的来说就是把一个数组看成是二叉树,就像上图 大堆和小堆分别是指根节点比孩子节 ...