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 of nodes set V into two parts such that s and t belong to different parts. The cut set is the subset of E with all edges connecting nodes in different parts. A minimum cut is the one whose cut set has the minimum summation of capacities. The size of a cut is the number of edges in the cut set. Please calculate the smallest size of all minimum cuts.
Input
The input contains several test cases and the first line is the total number of cases T (1≤T≤300).
Each case describes a network G, and the first line contains two integers n (2≤n≤200) and m (0≤m≤1000) indicating the sizes of nodes and edges. All nodes in the network are labelled from 1 to n.
The second line contains two different integers s and t (1≤s,t≤n) corresponding to the source and sink.
Each of the next m lines contains three integers u,v and w (1≤w≤255) describing a directed edge from node u to v with capacity w.
Output
For each test case, output the smallest size of all minimum cuts in a line.
Sample Input
2
4 5
1 4
1 2 3
1 3 1
2 3 1
2 4 1
3 4 2
4 5
1 4
1 2 3
1 3 1
2 3 1
2 4 1
3 4 3
Sample Output
2
3
题意
给你一个网络图,求最少边最小割
题解
如果流量全为1的话很容易知道最小边最小割=最小割
如果流量不为1,我们肯定要让哪里为1才可以得到答案
可以对边的权值进行hash,w-->w*hash+1
再跑最小割,跑完的答案%hash即可,这里hash>m就行
代码
#include<bits/stdc++.h>
using namespace std; const int maxn=1e5+;
const int maxm=2e5+;
int n,m,S,T;
int deep[maxn],q[];
int FIR[maxn],TO[maxm],CAP[maxm],COST[maxm],NEXT[maxm],tote; void add(int u,int v,int cap)
{
TO[tote]=v;
CAP[tote]=cap;
NEXT[tote]=FIR[u];
FIR[u]=tote++; TO[tote]=u;
CAP[tote]=;
NEXT[tote]=FIR[v];
FIR[v]=tote++;
}
bool bfs()
{
memset(deep,,sizeof deep);
deep[S]=;q[]=S;
int head=,tail=;
while(head!=tail)
{
int u=q[++head];
for(int v=FIR[u];v!=-;v=NEXT[v])
{
if(CAP[v]&&!deep[TO[v]])
{
deep[TO[v]]=deep[u]+;
q[++tail]=TO[v];
}
}
}
return deep[T];
}
int dfs(int u,int fl)
{
if(u==T)return fl;
int f=;
for(int v=FIR[u];v!=-&&fl;v=NEXT[v])
{
if(CAP[v]&&deep[TO[v]]==deep[u]+)
{
int Min=dfs(TO[v],min(fl,CAP[v]));
CAP[v]-=Min;CAP[v^]+=Min;
fl-=Min;f+=Min;
}
}
if(!f)deep[u]=-;
return f;
}
int maxflow()
{
int ans=;
while(bfs())
ans+=dfs(S,<<);
return ans;
}
void init()
{
tote=;
memset(FIR,-,sizeof FIR);
}
int main()
{
int _;
cin>>_;
while(_--)
{
init();
cin>>n>>m>>S>>T;
for(int i=,u,v,w;i<m;i++)
{
cin>>u>>v>>w;
add(u,v,w*+);
}
printf("%d\n",maxflow()%);
}
return ;
}
HDU 6214 Smallest Minimum Cut(最少边最小割)的更多相关文章
- 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 ...
- HDU 6214.Smallest Minimum Cut 最少边数最小割
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- hdu 6214 Smallest Minimum Cut[最大流]
hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...
- hdu 6214 Smallest Minimum Cut(最小割的最少边数)
题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...
- HDU 6214 Smallest Minimum Cut (最小割且边数最少)
题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...
- HDU 6214 Smallest Minimum Cut 最小割,权值编码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...
- hdu 6214 : Smallest Minimum Cut 【网络流】
题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...
- POJ 2914 Minimum Cut (全局最小割)
[题目链接] http://poj.org/problem?id=2914 [题目大意] 求出一个最小边割集,使得图不连通 [题解] 利用stoerwagner算法直接求出全局最小割,即答案. [代码 ...
- POJ 2914:Minimum Cut(全局最小割Stoer-Wagner算法)
http://poj.org/problem?id=2914 题意:给出n个点m条边,可能有重边,问全局的最小割是多少. 思路:一开始以为用最大流算法跑一下,然后就超时了.后来学习了一下这个算法,是个 ...
随机推荐
- LInux 阿里云系统遇到挖矿程序
参考 https://blog.csdn.net/qq_37837029/article/details/82314428 重要的一点,移除下面文件里面的定时任务 /var/spool/cron/cr ...
- day3 python 阿狸的进阶之路
函数概念: 1.为什要有函数 组织结构不清晰,可读性差,代码冗余,可扩展性差. 2.什么是函数 具备某一个功能的工具--->函数 事先准备工具->函数的定义 拿来就用. ...
- tfs对接数据-File
在使用tfs时,数据结构 /** * getFile */ @RequestMapping("/tfs/{fileName}") public ResponseEntity< ...
- 多媒体基础知识之PCM数据《 转》
多媒体基础知识之PCM数据 1.什么是PCM音频数据 PCM(Pulse Code Modulation)也被称为脉冲编码调制.PCM音频数据是未经压缩的音频采样数据裸流,它是由模拟信号经过采样.量化 ...
- mysql网课部分笔记
mysql> \s 查看当前数据库的状态 \c 取消当前所输入的命令或字符 ------------------------------------------------------- m ...
- JULIA BOORSTIN — Interview a Broadcaster!
JULIA BOORSTIN — Interview a Broadcaster! Share Tweet Share Tagged With: Interview a Broadcaster Stu ...
- JSP报错Syntax error, insert ";" to complete Statement
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in ...
- hexo发表博文的方式
本图片转自:简书:https://www.jianshu.com/p/a52b68794a6b 转自github:https://blog.minhow.com
- 单例模式 demo
// 用单例模式实现自定义颜色类 public class MyColor { private static MyColor _redColor = null; public static MyCol ...
- 吴裕雄 python 机器学习-KNN算法(1)
import numpy as np import operator as op from os import listdir def classify0(inX, dataSet, labels, ...