poj1273&&hdu1532
题解:
双倍经验
dinic模板题
然后ff过不了。。。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=;
int q[N*N],n,m,sum,dis[N],x,y,ans,f[N],z,a[N][N];
int bfs()
{
memset(dis,0xff,sizeof dis);
dis[]=;
int l=,r=;
q[]=;
while (l<r)
{
int j=q[++l];
for (int i=;i<=n;i++)
if (dis[i]<&&a[j][i]>)
{
dis[i]=dis[j]+;
q[++r]=i;
}
}
if (dis[n]>)return ;
return ;
}
int find(int x,int low)
{
int b=;
if (x==n)return low;
for (int i=;i<=n;i++)
if (a[x][i]>&&dis[i]==dis[x]+&&(b=find(i,min(low,a[x][i]))))
{
a[x][i]-=b;
a[i][x]+=b;
return b;
}
return ;
}
int main()
{
while (~scanf("%d%d",&m,&n))
{
memset(a,,sizeof a);
while (m--)
{
scanf("%d%d%d",&x,&y,&z);
a[x][y]+=z;
}
ans=;int t;
while (bfs())
while (t=find(,0x7fffffff))
ans+=t;
printf("%d\n",ans);
}
}
poj1273&&hdu1532的更多相关文章
- POJ1273&&Hdu1532 Drainage Ditches(最大流dinic) 2017-02-11 16:28 54人阅读 评论(0) 收藏
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- A过的题目
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...
- 【最大流FF模板】HDU1532&POJ1273
参照<挑战程序设计竞赛> #include<iostream> #include<cstdio> #include<cstdlib> #include& ...
- hdu1532&&poj1273 最大流
Dinic算法: 层次图:根据源点到该点的距离建图,这里设相邻的都差1. (下面部分转) 在这幅图中我们首先要增广1->2->4->6,这时可以获得一个容量为2的流,但是如果不建立4 ...
- hdu1532 (最大流入门,EK算法)
看着这个博客 然后敲了hdu1532这个入门题,算是对最大流有点理解了 #include <stdio.h> #include <string.h> #include < ...
- poj1273 Drainage Ditches Dinic最大流
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 76000 Accepted: 2953 ...
- 网络流模板(模板题:POJ1273)
模板题:POJ1273 EK: #include <queue> #include <cstdio> #include <cstring> #include < ...
- poj1273 Drainage Ditches (最大流板子
网络流一直没学,来学一波网络流. https://vjudge.net/problem/POJ-1273 题意:给定点数,边数,源点,汇点,每条边容量,求最大流. 解法:EK或dinic. EK:每次 ...
- HDU-1532 网络流裸题
HDU-1532 题意简单的来说就是从1点到n点,最大的流量是多少. 代码: #include<bits/stdc++.h> using namespace std; #define Fo ...
随机推荐
- 理解js的DOM操作
1.DOM结构——两个节点之间可能存在哪些关系以及如何在节点之间任意移动.document.documentElement 返回文档的根节点<html> document.body ...
- LinQ高级查询、组合查询、IQueryable集合类型
LinQ高级查询: 1.模糊查询(包含) Repeater1.DataSource = con.car.Where(r =>r.name.Contains(s)).ToList(); 2.开头 ...
- Ubuntu&Linux系统出现文件系统只读Read-only file system 的快速解决方法
问题描述: 周末运行盘平台服务程序,周一来操作系统卡顿,主进程已退出,重启进程时提示Read-only file system:新建目录和其他chmod -R等等操作都提示Read-only file ...
- java 与C# 时间格式 交互
方法一 C#端代码 IsoDateTimeConverter convert = new IsoDateTimeConverter(); string ret = JsonConvert.Serial ...
- 20145322何志威 《Java程序设计》课程总结
课程总结 每周读书笔记链接汇总 •第一周读书笔记 •第二周读书笔记 •第三周读书笔记 •第四周读书笔记 •第五周读书笔记 •第六周读书笔记 •第七周读书笔记 •第八周读书笔记 •第九周读书笔记 •第十 ...
- this 的理解
function foo(num){ console.log("foo:",+num); this.count++}foo.count =0for (var i=0; i<1 ...
- nxp的layerscape系列芯片中的rcw指定了一些什么信息
答:指定了一些可以配置的硬件信息(如可以配置uart相关的引脚功能).引导镜像(uboot)的读取地址以及从何种介质(flash,sd)启动系统的信息
- 安装xenserver6.5
安装之前的准备工作就不在赘述了,下边开始安装 1.安装界面 2.键盘模式选择默认-美式,ok 3.这里提醒你安装将清除磁盘信息,做好备份,选择ok. 4.这一步没有选择,要么继续,要么退回,选择Acc ...
- 迟到的thuwc&noiwc2018总结
已经4个多月没写博客了呢. thuwc和noiwc都炸了,接下来的一段时间都没怎么写题,靠文化课和游戏麻醉自己.这篇博客也算是向之前自闭.颓废的自己告别吧.. 先写一发游记: thuwc:Day1炸, ...
- js梳理
js引用类型 Object Function Array其他皆为基本类型,这和很多高级语言不一样,需要注意!!!! typeof对应基本类型来说更实用---- typeof undefined ...