题目链接:HDU6214

留一个链式前向星+Dinic模板(希望不要被某人发现,嘿嘿嘿)。

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define next Next
const int inf = 0x3f3f3f3f;
const int maxn=;
int level[maxn];
int iter[maxn];
int head[maxn],tot;
struct edge{
int to,cap,Next;
} e[]; ///此处应为边的两倍,加一条容量为0的反向边
void init(){
memset(head,-,sizeof(head));
tot=;
}
void add(int from,int to,int cap){
e[tot].Next=head[from];
e[tot].to=to;
e[tot].cap=cap;
head[from]=tot;
tot++;
}
void addedge(int from,int to,int cap){
add(from,to,cap);
add(to,from,);
}
void bfs(int s){
memset(level,-,sizeof(level));
queue<int> q;
level[s]=;
q.push(s);
while(!q.empty()){
int v=q.front(); q.pop();
for(int i=head[v];~i;i=e[i].Next){
edge &ed=e[i];
if(ed.cap>&&level[ed.to]<){
level[ed.to]=level[v]+;
q.push(ed.to);
}
}
}
}
int dfs(int v,int t,int f){
if(v==t) return f;
for(int &i=iter[v];~i;i=e[i].Next){
edge &ed=e[i];
if(ed.cap>&&level[v]<level[ed.to]){
int d=dfs(ed.to,t,min(f,ed.cap));
if(d>){
ed.cap-=d;
e[i^].cap+=d;
return d;
}
}
}
return ;
}
int max_flow(int s,int t){
int flow=;
while(){
bfs(s);
if(level[t]<) return flow;
memcpy(iter,head,sizeof(iter));
int f;
while((f=dfs(s,t,inf))>){
flow+=f;
}
}
}
int main()
{
int n,m,T;
scanf("%d",&T);
while(T--)
{
init();
int 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*+);
}
int ans = max_flow(s,t);
printf("%d\n",ans%);
}
return ;
}

HDU6214 Smallest Minimum Cut的更多相关文章

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

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

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

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

  3. Smallest Minimum Cut HDU - 6214(最小割集)

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

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

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

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

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

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

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

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

  9. 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数

    先最大流跑一遍 在残存网络上把满流边容量+1 非满流边容量设为无穷大 在进行一次最大流即可 (这里的边都不包括建图时用于反悔的反向边) #include<cstdio> #include& ...

随机推荐

  1. release判断系统

    #!/bin/bash # Name: Atomic Archive configuration script # Copyright Atomicorp, 2002-2018 # License: ...

  2. MySQL查询时,查询结果如何按照where in数组排序

    MySQL查询时,查询结果如何按照where in数组排序 在查询中,MySQL默认是order by id asc排序的,但有时候需要按照where in 的数组顺序排序,比如where in的id ...

  3. PHP将html内容转换为image图片

    /** * 将html内容转换为image图片 * @param $htmlcontent * @param $toimagepath * @author james.ou 2011-11-1 */ ...

  4. OOP面向对象形式的初使化配置

    init.php里: <?php use ElemeOpenApi\Config\Config; define("BASE_DIR", dirname(__FILE__) . ...

  5. 用Python实现小说中的汉字频率统计

     环境: Python 3的代码,亲测可用. 思路: 是先把每个字符提出来放在列表里:再过滤掉其中的标点符号:最后用字典对某个字出现的频率进行累加. 扩展: 用处很多,稍微改改,既可以用来统计小说或文 ...

  6. asm-offset.h 生成

    转自:https://blog.csdn.net/linglongqiongge/article/details/50008301 http://www.cnblogs.com/wendellyi/p ...

  7. python - unitest - 实战题目

    '''题目要求 1:自己写一个工具类,完成数学的加减乘除以及平方积操作2:对每个方法写2个用例3:针对测试用例选用不同的方法去执行,然后生成测试报告''' '''实现: 3个文件: work_2018 ...

  8. javaScript流程控制与函数

    流程控制 1.1 条件语句 分支结构 单向分支 if (条件表达式) { code... } <!DOCTYPE html> <html> <head> <m ...

  9. [python测试框架学习篇] 分享一个和adb相关的测试框架

    https://testerhome.com/topics/7106   (user: zteandallwinner     password: same to qq ) 264768502 · # ...

  10. TOJ 4493 Remove Digits 贪心

    4493: Remove Digits Description Given an N-digit number, you should remove K digits and make the new ...