HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】
Problem Description
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
Sample Input
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
3
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<sstream>
#include<cctype>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std; typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-;
const int INF=0x3f3f3f3f;
const int maxn=; int T;
int n,m,s,t;
int ans,flag,tot; int head[maxn],path[maxn],vis[maxn]; struct Edge
{
int from,to;
int cap;
int next;
}e[maxn]; void init()
{
tot=;
memset(head,-,sizeof(head));
memset(vis,,sizeof(vis));
memset(path,,sizeof(path));
} void add_edge(int u,int v,int w)
{
e[tot].from=u;
e[tot].to=v;
e[tot].cap=w;
e[tot].next=head[u];
head[u]=tot++;
} int bfs()
{
queue<int>q;
q.push(s);
vis[s]=;
path[s]=-;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u];i!=-;i=e[i].next)
{
int v=e[i].to;
if(e[i].cap>&&!vis[v])
{
path[v]=i;
vis[v]=;
if(v==t)
return ;
q.push(v);
}
}
}
return ;
} int EK()
{
int maxFlow=;
int flow,i;
while(bfs())
{
memset(vis,,sizeof(vis));
i=path[t];
flow=INF;
while(i!=-)
{
flow=min(flow,e[i].cap);
i=path[e[i].from];
}
i=path[t];
while(i!=-)
{
e[i].cap-=flow;
e[i^].cap+=flow;
i=path[e[i].from];
}
maxFlow+=flow;
}
return maxFlow;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
scanf("%d%d",&s,&t);
for(int i=;i<m;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add_edge(a,b,c*+);
add_edge(b,a,);
}
printf("%d\n",EK()%);
}
return ;
}
E K
HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】的更多相关文章
- hdu 6214 Smallest Minimum Cut(最小割的最少边数)
题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...
- hdu 6214 Smallest Minimum Cut[最大流]
hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...
- 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(最少边最小割)
Problem Description Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition o ...
- HDU 6214 Smallest Minimum Cut 最小割,权值编码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...
- HDU 6214 Smallest Minimum Cut (最小割且边数最少)
题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...
- hdu 6214 : Smallest Minimum Cut 【网络流】
题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...
- 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数
先最大流跑一遍 在残存网络上把满流边容量+1 非满流边容量设为无穷大 在进行一次最大流即可 (这里的边都不包括建图时用于反悔的反向边) #include<cstdio> #include& ...
- 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 ...
随机推荐
- 【NOIP模拟赛】黑红树 期望概率dp
这是一道比较水的期望概率dp但是考场想歪了.......我们可以发现奇数一定是不能掉下来的,因为若奇数掉下来那么上一次偶数一定不会好好待着,那么我们考虑,一个点掉下来一定是有h/2-1个红(黑),h/ ...
- MySQL使用笔记(七)排序和限制数据记录查询
By francis_hao Dec 17,2016 排序数据记录查询 排序是指将筛选出符合条件的数据进行有序排放,有升序(ASC(默认))方式和降序(DESC)方式. mysql> se ...
- 关于 WizTools.org RESTClient的使用
今天分享一个很好用的测试service的工具,很好用 提供两种方法使用这个东东. 第一种方法 通过cmd命令窗口. (1)cd C:\Users\li_weifeng\Desktop\c4d2(文件存 ...
- IDEA 用maven创建web项目编译时不能发布resources中的文件
1.在pom.xml加入 <build> <resources> <resource> <directory>${basedir}/src/main/j ...
- 膨胀、腐蚀、开、闭(matlab实现)
膨胀.腐蚀.开.闭运算是数学形态学最基本的变换. 本文主要针对二值图像的形态学 膨胀:把二值图像各1像素连接成分的边界扩大一层(填充边缘或0像素内部的孔): B=[0 1 0 1 1 1 ...
- codechef T6 Pishty and tree dfs序+线段树
PSHTTR: Pishty 和城堡题目描述 Pishty 是生活在胡斯特市的一个小男孩.胡斯特是胡克兰境内的一个古城,以其中世纪风格 的古堡和非常聪明的熊闻名全国. 胡斯特的镇城之宝是就是这么一座古 ...
- USACO_1.1_Your_Ride_Is_Here_(字符串+水题)
描述 http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=ride 给出两个由大写字母组成,长度不大于$6$的字符串. 将字符串中的各字母的字典 ...
- 【洛谷 P1645】 序列 (差分约束)
题目链接 差分约束. 设\(s[i]\)表示前\(i\)个位置有多少个数,那么对于一个限制条件\((L,R,C)\),显然有 \[s[R]-s[L-1]>=C\] 于是连一条\(L-1\)到\( ...
- [bzoj3098]Hash Killer 2——哈希
题目 这天天气不错,hzhwcmhf神犇给VFleaKing出了一道题: 给你一个长度为N的字符串S,求有多少个不同的长度为L的子串. 子串的定义是S[l].S[l + 1].- S[r]这样连续的一 ...
- autoKeras入门
测试本地mnist数据集 图片只用500张,450张做train与50张test, 代码如下: # conding:utf-8 import os os.environ[' import numpy ...