hdu 6214 Smallest Minimum Cut[最大流]
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[最大流]的更多相关文章
- 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 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(最少边最小割)
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(最小割的最少边数)
题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...
- hdu 6214 : Smallest Minimum Cut 【网络流】
题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...
- Smallest Minimum Cut HDU - 6214(最小割集)
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- 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 ...
随机推荐
- WPF事件中的sender就是事件源
可以看到wpf中所有的事件都是这个格式: private void btnTest_Click(object sender, RoutedEventArgs e) { Button btn = (B ...
- jQuery 自定义方法(扩展方法)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- mysql 远程链接问题
问题描述: 从一台linux远程连接另一台linux上的MySQL, 出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.x ...
- ComboBox ItemHeight 再高一点
public static void BindData(this ComboBox box, List<KeyValuePair<long, string>> data) { ...
- [转]Web API Introduction to OData Services using ASP.NET Web API
本文转自:http://mahedee.net/tag/web-api/ What is OData? OData Stands for Open Data Protocol. It is a dat ...
- 特殊引用类型(string)
private string FuncWithParameters(int param1, String param2, List<string> param3) { // 我们在这里改变 ...
- 了解:C#三维数组和锯齿数值
此文章,只需了解,用到的不多. string[,,] three = new string[2, 3, 5]; //定义一个三维数组,给数组分别辅助2,3,5 对此数组的解释://有2个二维数组,每 ...
- C++测验代码
/* 返回字符串前n位和返回整数前n位 */ #include <iostream> unsigned long left(unsigned long num, int n); char ...
- spring_boot启动报错
配置好pom文件后,在controller加注解,如下: 运行后报错!!! 发现配置加的是多此一举,修改为下边的,运行OK
- PAT 1061. Dating
题是别人出的,不按她的想法来也没办法,真心想k一顿 #include <cstdio> #include <cstdlib> using namespace std; cons ...