hdu 6214 Smallest Minimum Cut[最大流]

题意:求最小割中最少的边数。

题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦。。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define CLR(a,b) memset((a),(b),sizeof((a)))
typedef long long ll;
const int N = ;
const int inf = 0x3f3f3f3f;
int n, m, S, T;
int dep[N], cur[N];
int head[N];
struct Edge{
int v, c, nex;
Edge(int _v=,int _c=,int _nex=):v(_v),c(_c),nex(_nex){}
};
vector<Edge>E;
void add(int u,int v,int c){E.push_back(Edge(v,c,head[u]));head[u]=E.size()-;} bool bfs() {
queue<int> q;
CLR(dep, -);
q.push(S); dep[S] = ;
while(!q.empty()) {
int u = q.front(); q.pop();
for(int i = head[u]; ~i; i = E[i].nex) {
int v = E[i].v;
if(E[i].c && dep[v] == -) {
dep[v] = dep[u] + ;
q.push(v);
}
}
}
return dep[T] != -;
}
int dfs(int u, int flow) {
if(u == T) return flow;
int w, used=;
for(int i = head[u]; ~i; i = E[i].nex) {
int v = E[i].v;
if(dep[v] == dep[u] + ) {
w = flow - used;
w = dfs(v, min(w, E[i].c));
E[i].c -= w; E[i^].c += w;
if(v) cur[u] = i;
used += w;
if(used == flow) return flow;
}
}
if(!used) dep[u] = -;
return used;
}
int dinic() {
int ans = ;
while(bfs()) {
for(int i = ; i <= T;i++)
cur[i] = head[i];
ans += dfs(S, inf);
}
return ans;
}
int main() {
int t, i, u, v, w;
scanf("%d", &t);
while(t--) {
E.clear(); CLR(head, -);
scanf("%d%d", &n, &m);
scanf("%d%d", &S, &T);
for(i = ; i <= m; ++i) {
scanf("%d%d%d", &u, &v, &w);
add(u, v, w*+); add(v, u, );
}
int ans = dinic()%;
printf("%d\n", ans);
}
return ;
}

249ms

hdu 6214 Smallest Minimum Cut[最大流]的更多相关文章

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

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

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

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

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

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

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

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

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

随机推荐

  1. 聚焦小游戏技术生态,腾讯游戏云GAME-TECH落地厦门

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯游戏云 发表于云+社区专栏 2018迎来了小游戏元年,据<2018年小游戏行业白皮书>显示:2018年小游戏市场规模预 ...

  2. find ip from hostname or find hostname from ip

    1. find ip from hostname ping <hostname> 2.fin hostname from ip nslookup <ip>

  3. Iterator和ListIterator的区别 ---面试题

    Iterator和ListIterator的区别是什么? 下面列出了他们的区别: Iterator可用来遍历Set和List集合,但是ListIterator只能用来遍历List. Iterator对 ...

  4. AngularJS的日期格式化去掉秒

    <td>订单创建时间:{{item.odatetime.substring(0,16)}}</td>

  5. java向上转型的问题

    import java.util.Arrays;import java.util.HashSet;import java.util.Set;class A{ private String s1 = & ...

  6. Redis单机数据迁移至Sentinel集群

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  7. request对象域和转发

    1.request是一个域对象,具备以下方法 setAttribute(string name,Object O) getAttribute(String name) removeAttribute( ...

  8. 四 Scatter/Gather

    scatter/gather用于描述从Channel中读取或者写入到Channel的操作. 分散(scatter):从Channel中读取在读操作中将读取的数据写入多个Buffer中.因此,Chann ...

  9. poj 1155 树形背包

    http://blog.csdn.net/libin56842/article/details/9908199 树形背包: 首先是建树,每个结构体为一个节点,包括下一个点序号,值,和next. tre ...

  10. JavaScript里面的居民们2-字符串

    基于HTML,实现需求 按照HTML中按钮的描述以此实现功能 计算结果显示在 id 为 result 的 P 标签中 <!DOCTYPE html> <html> <he ...