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 ...
随机推荐
- 搭建Firekylin博客
搭建步骤 1).安装 Node.js curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash - yum - ...
- Chrome搜索设置
https://encrypted.google.com/ncr https://encrypted.google.com/search?{google:RLZ}{google:acceptedSug ...
- React组件绑定this的四种方式
题图 By HymChu From lnstagram 用react进行开发组件时,我们需要关注一下组件内部方法this的指向,react定义组件的方式有两种,一种为函数组件,一种为类组件,类组件内部 ...
- CSS Ul(列表样式)
CSS Ul(列表样式) CSS列表属性作用如下: 设置不同的列表项标记为有序列表 设置不同的列表项标记为无序列表 设置列表项标记为图像 一.列表 在HTML中,有两种类型的列表: 无序列表 - 列表 ...
- React绑定this的三种方式
React可以使用React.createClass.ES6 classes.纯函数3种方式构建组件.使用React.createClass会自动绑定每个方法的this到当前组件,但使用ES6 cla ...
- Python-自省机制
help 如果说能够通过一个函数就能够学会 Python,那这个函数一定就是 Python 提供的第一 个自带说明 help().help 函数的作用就是查看对象的帮组文档.比如: >> ...
- SaltStack本地管理无master模式-第八篇
Salt本地管理应用场景 1.在边缘节点服务器非常少没有Salt-master 2.零售店,电影院等弱网络环境没有Salt-master 3.快速部署单个服务没有Salt-master 实现 一,安装 ...
- MCM写作
MCM 写作 引言的写作 对赛题的解读. 对现有研究成果的松树与评论 对解题思路和主要方法进行简介 引言第一句话是最重要的,应该激发读者阅读兴趣,应该浅显易懂,不用或者少用数学公式 赛题选定以后要首先 ...
- JavaScript的动态特性(通过eval,call,apply和bind来体现)
JavaScript的动态特性(通过eval,call,apply和bind来体现) JavaScript是一种基于面向对象的.函数式的.动态的编程语言.现在发展到已经可以用在浏览器和服务器端了. 这 ...
- mysql 索引相关问题
mysql中key .primary key .unique key 与index区别 https://blog.csdn.net/nanamasuda/article/details/5254317 ...