题目链接: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. k8s搭建WebUI--Dashborad管理界面

    k8s的webUI管理界面可以更好更直观更便捷的让我们去管理我们的k8s集群. 我们知道,由于某些原因我们无法直接拉取dashboard的镜像,但是国内有些人已经将镜像下载到dockerhub中可以给 ...

  2. idea 关于高亮显示与选中字符串相同的内容踩过的坑

    由 Eclipse 切换到 idea 遇到了很多不熟的地方和踩过的坑,下面记录 idea 关于高亮显示与选中字符串相同的内容踩过的坑. IDEA 2017.2.1 版本修改 Identifier un ...

  3. pre-commit钩子,代码质量检查

    目前基本使用三款js代码质量检查工具: jslint, jshint, eslint.许多IDE里面也有对应的检查插件,在每次ctrl + s 保存文件的时候,检查当前文件是否符合规范,保证代码质量. ...

  4. 【linux】【CPU】【x86】平台说明

    节选自 <鸟哥的linux私房菜> http://cn.linux.vbird.org/linux_basic/0520rpm_and_srpm_1.php 操作硬件平台:这是个很好玩的地 ...

  5. leetcode-25-exercise_string&array

    14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array ...

  6. SQL防止重复提交和Filter

    /class User package com.neuedu.bean; import java.io.Serializable; public class User implements Seria ...

  7. POJ 1791 Parallelogram Counting(求平行四边形数量)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  8. ACM Changchun 2015 L . House Building

    Have you ever played the video game Minecraft? This game has been one of the world's most popular ga ...

  9. js基础之javascript的存在形式和js代码块在页面中的存放位置和 CSS 对比

    1.存在形式 文件 如: <script src='js/jc.js'></script> 前页面 <script type='text/javascript'>a ...

  10. kafka消息的可靠性

    本文来自网易云社区 作者:田宏增 Kafka的高可靠性的保障来源于其健壮的副本(replication)策略.通过调节其副本相关参数,可以使得Kafka在性能和可靠性之间运转的游刃有余.Kafka从0 ...