Smallest Minimum Cut

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1181    Accepted Submission(s): 473

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
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6216 6215 6214 6213 6212 
 
题意:求最少边数的最小割
注意:增广路和最小割集没有关系
方案一:先跑一边最大流,如果边满流,容量+1;否者,容量inf。再跑一遍最大流
方案二:对容量进行处理,容量*(大数或者边数M+1)+1,跑一边最大流Maxflow,处理前的最大流为Maxflow/(M+1),最少边数的最小割集为Maxflow%(M+1)。说明:原图的最小割为为x1、x2、x3...,即∑x,处理后的最小割为∑x*(M+1)+B,其中B为原图最小割边的数量,如果能有边数更少的情况,处理后最小割也会相应的减少,所以处理后得到的B即为最少边数。
代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define bug(x) cout<<"bug"<<x<<endl;
#define PI acos(-1.0)
#define eps 1e-8
const int N=1e5+,M=1e5+;
const int inf=0x3f3f3f3f;
const ll INF=1e18+,mod=1e9+;
struct edge
{
int from,to,cap,flow;
};
vector<edge>es;
vector<int>G[N];
bool vis[N];
int dist[N];
int iter[N];
void init(int n)
{
for(int i=; i<=n+; i++) G[i].clear();
es.clear();
}
void addedge(int from,int to,int cap)
{
es.push_back((edge)
{
from,to,cap,
});
es.push_back((edge)
{
to,from,,
});
int x=es.size();
G[from].push_back(x-);
G[to].push_back(x-);
}
bool BFS(int s,int t)
{
memset(vis,false,sizeof(vis));
queue <int> Q;
vis[s]=true;
dist[s]=;
Q.push(s);
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for (int i=; i<G[u].size(); i++)
{
edge &e=es[G[u][i]];
if (!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=;
dist[e.to]=dist[u]+;
Q.push(e.to);
}
}
}
return vis[t];
}
int DFS(int u,int t,int f)
{
if(u==t||f==) return f;
int flow=,d;
for(int &i=iter[u]; i<G[u].size(); i++)
{
edge &e=es[G[u][i]];
if(dist[u]+==dist[e.to]&&(d=DFS(e.to,t,min(f,e.cap-e.flow)))>)
{
e.flow+=d;
es[G[u][i]^].flow-=d;
flow+=d;
f-=d;
if(f==) break;
}
}
return flow;
}
int Maxflow(int s,int t)
{
int flow=;
while(BFS(s,t))
{
memset(iter,,sizeof(iter));
int d=;
while(d=DFS(s,t,inf)) flow+=d;
}
return flow;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,s,t;
scanf("%d%d",&n,&m);
scanf("%d%d",&s,&t);
for(int i=; i<=m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
addedge(u,v,w);
}
Maxflow(s,t);
for(int i=; i<es.size(); i+=)
{
if(es[i].flow==es[i].cap) es[i].cap++;
else es[i].cap=inf;
}
printf("%d\n",Maxflow(s,t));
init(n);
}
return ;
}

方案一

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define bug(x) cout<<"bug"<<x<<endl;
#define PI acos(-1.0)
#define eps 1e-8
const int N=1e5+,M=1e5+;
const int inf=0x3f3f3f3f;
const ll INF=1e18+,mod=1e9+;
struct edge
{
int from,to,cap,flow;
};
vector<edge>es;
vector<int>G[N];
bool vis[N];
int dist[N];
int iter[N];
void init(int n)
{
for(int i=; i<=n+; i++) G[i].clear();
es.clear();
}
void addedge(int from,int to,int cap)
{
es.push_back((edge)
{
from,to,cap,
});
es.push_back((edge)
{
to,from,,
});
int x=es.size();
G[from].push_back(x-);
G[to].push_back(x-);
}
bool BFS(int s,int t)
{
memset(vis,false,sizeof(vis));
queue <int> Q;
vis[s]=true;
dist[s]=;
Q.push(s);
while(!Q.empty())
{
int u=Q.front();
Q.pop();
for (int i=; i<G[u].size(); i++)
{
edge &e=es[G[u][i]];
if (!vis[e.to]&&e.cap>e.flow)
{
vis[e.to]=;
dist[e.to]=dist[u]+;
Q.push(e.to);
}
}
}
return vis[t];
}
int DFS(int u,int t,int f)
{
if(u==t||f==) return f;
int flow=,d;
for(int &i=iter[u]; i<G[u].size(); i++)
{
edge &e=es[G[u][i]];
if(dist[u]+==dist[e.to]&&(d=DFS(e.to,t,min(f,e.cap-e.flow)))>)
{
e.flow+=d;
es[G[u][i]^].flow-=d;
flow+=d;
f-=d;
if(f==) break;
}
}
return flow;
}
int Maxflow(int s,int t)
{
int flow=;
while(BFS(s,t))
{
memset(iter,,sizeof(iter));
int d=;
while(d=DFS(s,t,inf)) flow+=d;
}
return flow;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,s,t;
scanf("%d%d",&n,&m);
scanf("%d%d",&s,&t);
for(int i=; i<=m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
addedge(u,v,w*(m+)+);
}
printf("%d\n",Maxflow(s,t)%(m+));
init(n);
}
return ;
}

方案二

HDU 6214.Smallest Minimum Cut 最少边数最小割的更多相关文章

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

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

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

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

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

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

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

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

  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. Smallest Minimum Cut HDU - 6214(最小割集)

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 Problem Description Consider a network G=(V,E) w ...

随机推荐

  1. python开发购物车

    1 业务需求 商品中心 显示库存的商品 商品能够加入到购物车 个人中心 购物车 修改购物车的商品 下单 完成的订单 订单详情 账户余额 2 代码实现 # 定义全局变量信息 # 商品编号信息 goods ...

  2. cookie.js插件的案例

    cookie.js插件的案例: https://github.com/jaywcjlove/cookie.js/blob/master/README.md    文档  api   在这里即可查看用法 ...

  3. Pymysql部分

    安装: 1 执行SQL import pymysql # 创建连接 conn = pymysql.connect(host='172.30.2.233', port=3306, user='root' ...

  4. HTML的day1 HTML的标签

    a标签和锚点 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  5. Linux背背背(2)

    目录: 1.简单命令 2.目录切换命令 3.扩展命令 简单命令 ls 语法1:#ls [路径]            表示列出指定路径下的文件夹和文件的名字,如果路径没有指定则列出当前路径下的 语法2 ...

  6. Chapter4 复杂度分析(下):浅析最好,最坏,平均,均摊时间复杂度

    四个复杂度分析: 1:最好情况时间复杂度(best case time complexity) 2:最坏情况时间复杂度(worst case time complexity) 3:平均情况时间复杂度( ...

  7. Vue 封装的loading组件

    <template> <div class="loadEffect"> <span></span> <span>< ...

  8. java 错误

    ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 解决在程序最后加一条语句system. ...

  9. 实战ELK(4)Metricbeat 轻量型指标采集器

    一.介绍 用于从系统和服务收集指标.从 CPU 到内存,从 Redis 到 Nginx,Metricbeat 能够以一种轻量型的方式,输送各种系统和服务统计数据. 1.系统级监控,更简洁(轻量型指标采 ...

  10. ATS配置自定义日志

    修改records.config,开启日志自定义功能 更改日志目录,默认日志存放在/var/log/trafficserver: CONFIG proxy.config.log.logfile_dir ...