bzoj3931: [CQOI2015]网络吞吐量(spfa+网络流)
3931: [CQOI2015]网络吞吐量
题目:传送门
题解:
现在有点难受....跳了一个多钟...菜啊...
题意都把做法一起给了....最短路+网路流啊。
不想说话...记得开long long
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#define qread(x)x=read();
using namespace std;
typedef long long LL;
const LL INF=(1LL<<);
inline int read()
{
int f=,x=;char ch;
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return f*x;
}
struct edge
{
int x,y,next;LL d;
}e[];int last1[],len1;
void ins1(int x,int y,LL d)
{
len1++;
e[len1].x=x;e[len1].y=y;e[len1].d=d;
e[len1].next=last1[x];last1[x]=len1;
}
struct node
{
int x,y,next,other;LL d;
}a[];int last[],len;
void ins(int x,int y,LL d)
{
int k1,k2;
len++;k1=len;
a[len].x=x;a[len].y=y;a[len].d=d;
a[len].next=last[x];last[x]=len; len++;k2=len;
a[len].x=y;a[len].y=x;a[len].d=;
a[len].next=last[y];last[y]=len; a[k1].other=k2;
a[k2].other=k1;
}
int n,m;
int st,ed,head,tail;
int list[],h[];
bool bt_h()
{
memset(h,,sizeof(h));h[st]=;
list[]=st;head=;tail=;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]== && a[k].d>)
{
h[y]=h[x]+;
list[tail++]=y;
}
}
head++;
}
if(h[ed]>)return true;
return false;
}
LL find_flow(int x,LL flow)
{
if(x==ed)return flow;
LL s=,t;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]==(h[x]+) && a[k].d> && flow>s)
{
t=find_flow(y,min(a[k].d,flow-s));
s+=t;
a[k].d-=t;a[a[k].other].d+=t;
}
}
if(s==)h[x]=;
return s;
}
LL dd[];
bool v[];
void spfa()
{
for(int i=;i<=n;i++)dd[i]=INF;
memset(v,true,sizeof(v));
memset(list,,sizeof(list));
list[]=st;dd[st]=;head=;tail=;
while(head!=tail)
{
int x=list[head];
for(int k=last1[x];k;k=e[k].next)
{
int y=e[k].y;
if(dd[y]>dd[x]+e[k].d)
{
//printf("%d %d\n",x,y);
dd[y]=dd[x]+e[k].d;
if(v[y]==true)
{
v[y]=false;
list[tail]=y;tail++;if(tail==n+)tail=;
}
}
}
list[head]=;
head++;if(head==n+)head=;
v[x]=true;
}
}
int main()
{
//freopen("network.in","r",stdin);
//freopen("network.out","w",stdout);
qread(n);qread(m);
len1=;memset(last1,,sizeof(last));
len=;memset(last,,sizeof(last));
memset(list,,sizeof(list));
st=;ed=n*;
for(int i=;i<=m;i++)
{
int x,y;LL d;
qread(x);qread(y);scanf("%lld",&d);
ins1(x,y,d);
ins1(y,x,d);
//printf("%d %d %lld\n",x,y,d);
}
spfa();
memset(list,,sizeof(list));
for(int i=;i<=n;i++)
{
LL x;scanf("%lld",&x);
if(i!= && i!=n)
{
ins(i,i+n,x);
//printf("%d %d\n",i,i+n);
}
}
ins(st,+n,INF);
ins(n,ed,INF);
for(int i=;i<=n;i++)
{
for(int k=last1[i];k;k=e[k].next)
{
int y=e[k].y;
if(dd[i]+e[k].d==dd[y])
{
ins(i+n,y,INF);
}
}
}
LL ans=;
while(bt_h())
ans+=find_flow(st,INF);
printf("%lld\n",ans);
return ;
}
bzoj3931: [CQOI2015]网络吞吐量(spfa+网络流)的更多相关文章
- [CQOI2015]网络吞吐量(网络流+SPFA)
[CQOI2015]网络吞吐量 题目描述 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的 ...
- bzoj3931: [CQOI2015]网络吞吐量
将最短路图找出来,跑maxflow即可.有注意到数据范围.然后输出的时候%dWA了三次QAQ... #include<cstdio> #include<cstring> #in ...
- bzoj千题计划136:bzoj3931: [CQOI2015]网络吞吐量
http://www.lydsy.com/JudgeOnline/problem.php?id=3931 在最短路网络上跑最大流 #include<queue> #include<c ...
- 3931: [CQOI2015]网络吞吐量【网络流】
网络吞吐量(network)题目描述路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的地,路 ...
- [bzoj3931][CQOI2015]网络吞吐量——最短路+网络流
题目 传送门 题解 第一次一遍就AC一道bzoj上的题,虽然是一道水题... 我们做一边最短路,求出每个点的dist,然后再做一次类似spfa的操作,求出每个点是否可以用于建图. 在新图上拆点跑一边d ...
- BZOJ3931 [CQOI2015]网络吞吐量(最大流)
没啥好说的,有写过类似的,就是预处理出最短路上的边建容量网络. #include<cstdio> #include<cstring> #include<queue> ...
- 【最短路】【最大流】bzoj3931 [CQOI2015]网络吞吐量
跑出最短路图,然后把结点拆点跑最大流. #include<cstdio> #include<queue> #include<cstring> #include< ...
- bzoj 3931: [CQOI2015]网络吞吐量 -- 最短路+网络流
3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec Memory Limit: 512 MB Description 路由是指通过计算机网络把信息从源地址传输到目的地址 ...
- 【BZOJ3931】[CQOI2015]网络吞吐量 最大流
[BZOJ3931][CQOI2015]网络吞吐量 Description 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为 ...
随机推荐
- DML语句(添加、更新和删除记录)
a.添加记录(一次插入一行记录) insert into 表名(字段名,字段名...) values (字段值,字段值...) insert into person ...
- BZOJ——1602: [Usaco2008 Oct]牧场行走 || 洛谷—— P2912 [USACO08OCT]牧场散步Pasture Walking
http://www.lydsy.com/JudgeOnline/problem.php?id=1602 || https://www.luogu.org/problem/show?pid=2912 ...
- 常用类属于哪些jar包
1.@requestmapping注解,属于org.springframework.web.bind.annotation包下.org.springframework.web jar包. 2.@Res ...
- apk去广告工具(利用apktool去除apk文件里的广告)
基本知识 apk安装包的文件结构 以知名桌面软件“LauncherPro”为例,apk安装包文件目录: 文件目录如下: - META-INF - res - anim - color - drawab ...
- Java面试中常问的数据库方面问题
MySQL 为什么用自增列作为主键 如果我们定义了主键(PRIMARY KEY),那么InnoDB会选择主键作为聚集索引.如果没有显式定义主键,则InnoDB会选择第一个不包含有NULL值的唯一索引作 ...
- 关闭 sftp
vi /etc/ssh/sshd_config 注释掉这行Subsystem sftp /usr/libexec/openssh/sftp-server /etc/rc.d/init.d/ss ...
- UI组件之TextView及其子类(一)TextView和EditText
先来整理一下TexView,EditView的使用方法. Textview是最主要的组件.直接继承了View,也是众多组件的父类.所以了解她的属性会对学习其它组件非常有帮助. TextView的属性: ...
- CoreData 从入门到精通(三)关联表的创建
上篇博客中讲了 CoreData 里增删改查的使用,学到这里已经可以应对简单的数据存储需求了.但是当数据模型复杂起来时,例如你的模型类中除了要存储 CoreData 里支持的数据类型外,还有一些自定义 ...
- 神经网络预测mnist时候如果不归一化,则准确率仅仅10%下文作者svm也遇到了。
转自:http://blog.csdn.net/jeryjeryjery/article/details/72649320 这两天用Python来实现手写数字识别,刚开始用原始数据进行训练,结果预测结 ...
- 【原创】Linux下的ngix服务器安装步骤
1.首先下载ngix的源码linux版本[1.5.8版本] http://nginx.org/en/download.html 2.下载PCRE library,是安装ngix的必备包之一 [root ...