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(最少边最小割)的更多相关文章

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

  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(最小割的最少边数)

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

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

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

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

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

  7. hdu 6214 : Smallest Minimum Cut 【网络流】

    题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...

  8. POJ 2914 Minimum Cut (全局最小割)

    [题目链接] http://poj.org/problem?id=2914 [题目大意] 求出一个最小边割集,使得图不连通 [题解] 利用stoerwagner算法直接求出全局最小割,即答案. [代码 ...

  9. POJ 2914:Minimum Cut(全局最小割Stoer-Wagner算法)

    http://poj.org/problem?id=2914 题意:给出n个点m条边,可能有重边,问全局的最小割是多少. 思路:一开始以为用最大流算法跑一下,然后就超时了.后来学习了一下这个算法,是个 ...

随机推荐

  1. win10 解决 WMI Provider Host 占用CPU过高问题

    真心懒得写Blog,但是之前遇到这个问题在网上查了一大圈,几乎一摸一样都是让关防火墙等服务的,然而对于我来说,并没有毛线用. 无奈,直接去微软社区查,还真有一篇问题解决方案.顺手翻译一下放在这里,希望 ...

  2. SVM视频跟踪

    # -*- coding: utf-8 -*- """ Created on Thu Nov 8 21:44:12 2018 @author: xg "&quo ...

  3. UI5-学习篇-8-本地SAP WEB IDE开发

    1.本地SAP WEB IDE下载 UI5-学习篇-3-Local SAP WEB IDE下载 2.启动Orion服务 解压SAP WEB IDE文件后,双击Orion应用程序启动服务,如下图: 服务 ...

  4. 页面中onclick事件引号问题

    第一种:html中onclick调用事件 <p id="txt" onclick="changeSize()">加括弧的changeSize()&l ...

  5. DATASNAP远程方法返回TSTREAM正解(转咏南兄)

    DATASNAP远程方法返回TSTREAM正解 DATASNAP远程方法返回TSTREAM,如果数据大小超过32K是会报错的.许多DELPHIER栽在这个上头,甚至开始怀疑TSTREAM返回数据的可行 ...

  6. 公网Ip和私网ip

    IP可以分为Public IP 和 Private IP,出现这种规划的原因在于IPv4所能表示的IP太少而电脑太多以至于不够用,然而只有Public IP才能直接连接上网络,所以对于那些公司,学校, ...

  7. Kotlin语言编程技巧集

    空语句 Kotlin 语言中的空语句有 {} Unit when (x) { 1 -> ... 2 -> ... else -> {} // else -> Unit } Wh ...

  8. 配置nginx实现windows/iis应用负载均衡(转载)

    配置nginx实现windows/iis应用负载均衡   nginx是俄罗斯人开发的一款跨平台的高性能HTTP和反向代理服务器,可以利用它实现web应用服务器的负载均衡. 反向代理是指将用户请求通过代 ...

  9. KVM虚拟化技术(六)磁盘管理

    KVM支持的虚拟磁盘类型 raw 这并非是一种真正的磁盘格式,而是代表虚拟机所使用的原始镜像:它并不存储元数据,因此可以作为保证虚拟机兼容性的候选方案,然而也正因为 它不存储元数据,因此不能支持某些高 ...

  10. MySQL查询提示

    MySQL查询提示: 1.LOW_PROPRITY,HIGHT_PRIORITY 作用:指定sql语句的运行优先级,会将加了HIGHT_PROPRITY提示的sql调度到表访问队列的最前面 限制:仅对 ...