HDU6214 Smallest Minimum Cut
题目链接: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的更多相关文章
- HDU-6214 Smallest Minimum Cut(最少边最小割)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 Problem Description Consider a network G=(V,E) w ...
- HDU 6214.Smallest Minimum Cut 最少边数最小割
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- 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[最大流]
hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...
- 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(最小割边最小割)
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 ...
- 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 【网络流】
题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...
- 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数
先最大流跑一遍 在残存网络上把满流边容量+1 非满流边容量设为无穷大 在进行一次最大流即可 (这里的边都不包括建图时用于反悔的反向边) #include<cstdio> #include& ...
随机推荐
- Flask-数据与路由
数据 图书数据库的地址 # 基地址 http://t.yushu.im # 关键字搜索 http://t.yushu.im/v2/book/search?q={}&start={}&c ...
- 【linux】【CPU】【x86】平台说明
节选自 <鸟哥的linux私房菜> http://cn.linux.vbird.org/linux_basic/0520rpm_and_srpm_1.php 操作硬件平台:这是个很好玩的地 ...
- html5音频audio对象封装成vue组件的方式调用以及setTimeout如何在vue2生效 (vue2正在熟悉中,ajax还是用jQuery来写舒服些,里面含有一些php写法可略过) 此网页应用在PC不考虑手机端
// vue2 组件封装如下: <template> <div> <div><!--vue element 组件的引用 Switch 开关 不懂请自行百度(重 ...
- php生成zip压缩文件的方法,支持文件和压缩包路径查找
/* * new creatZip($_dir,$_zipName); *@ _dir是被压缩的文件夹名称,可使用路径,例 'a'或者'a/test.txt'或者'test.txt' *@ _zipN ...
- CF 510b Fox And Two Dots
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on ...
- zoj 4057
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...
- python爬取+使用网易卡搭作品数量api
第一步,当然是打开浏览器~ 然后打开卡搭~ 看着熟悉的界面,是不是有点不知所措? 这就对了,咱找点事情干干. 随便找个倒霉蛋,比如这位:"混世大王",打开他的主页! 按下f12(我 ...
- python - work5 - 类与对象 - 拓展题
''' 5:购物车类,包含的功能如下,请自行设计这个类以及类里面的方法:1)用户输入工资后,打印商品列表(商品列表自行设计展示模式)2)允许用户根据商品编号去选择商品3)用户选择商品后,检查余额是否足 ...
- shutil——高级的 文件、文件夹、压缩包 处理模块
高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length])复制文件内容(不包含元数据)从类文件对象src到类文件对dst.可选参数leng ...
- Python爬虫selenium、PhanmJs
selenium:可以模拟鼠标进行一些操作 实例1:实现自动打开google浏览器,进行百度搜索,并关闭浏览器 from selenium import webdriver from time imp ...