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+网络流)的更多相关文章

  1. [CQOI2015]网络吞吐量(网络流+SPFA)

    [CQOI2015]网络吞吐量 题目描述 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的 ...

  2. bzoj3931: [CQOI2015]网络吞吐量

    将最短路图找出来,跑maxflow即可.有注意到数据范围.然后输出的时候%dWA了三次QAQ... #include<cstdio> #include<cstring> #in ...

  3. bzoj千题计划136:bzoj3931: [CQOI2015]网络吞吐量

    http://www.lydsy.com/JudgeOnline/problem.php?id=3931 在最短路网络上跑最大流 #include<queue> #include<c ...

  4. 3931: [CQOI2015]网络吞吐量【网络流】

    网络吞吐量(network)题目描述路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的地,路 ...

  5. [bzoj3931][CQOI2015]网络吞吐量——最短路+网络流

    题目 传送门 题解 第一次一遍就AC一道bzoj上的题,虽然是一道水题... 我们做一边最短路,求出每个点的dist,然后再做一次类似spfa的操作,求出每个点是否可以用于建图. 在新图上拆点跑一边d ...

  6. BZOJ3931 [CQOI2015]网络吞吐量(最大流)

    没啥好说的,有写过类似的,就是预处理出最短路上的边建容量网络. #include<cstdio> #include<cstring> #include<queue> ...

  7. 【最短路】【最大流】bzoj3931 [CQOI2015]网络吞吐量

    跑出最短路图,然后把结点拆点跑最大流. #include<cstdio> #include<queue> #include<cstring> #include< ...

  8. bzoj 3931: [CQOI2015]网络吞吐量 -- 最短路+网络流

    3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec  Memory Limit: 512 MB Description 路由是指通过计算机网络把信息从源地址传输到目的地址 ...

  9. 【BZOJ3931】[CQOI2015]网络吞吐量 最大流

    [BZOJ3931][CQOI2015]网络吞吐量 Description 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为 ...

随机推荐

  1. LaTeX 图片色偏解决方法

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50327113 在LaTeX的编辑模式中 ...

  2. nutch+hadoop 配置使用

    nutch+hadoop 配置使用 配置nutch+hadoop 1,下载nutch.如果不需要特别开发hadoop,则不需要下载hadoop.因为nutch里面带了hadoop core包以及相关配 ...

  3. lucene构建restful风格的简单搜索引擎服务

    来自于本人博客: lucene构建restful风格的简单搜索引擎服务 本人的博客如今也要改成使用lucene进行全文检索的功能,因此在这里把代码贴出来与大家分享 一,文件夹结构: 二,配置文件: 总 ...

  4. 四旋翼飞行器Quadrotor飞控之 PID调节(參考APM程序)

    做四轴也有一段时间了.近期一直在做PID方面的工作. 如今四轴基本能够实现室内比較稳定的飞行,操控手感也能够接受.稍后上试飞视频.在此把一些PID方面的经验总结总结和大家分享一下. 首先介绍一下大概的 ...

  5. Linux内核中进程上下文和中断上下文的理解

    參考: http://www.embedu.org/Column/Column240.htm http://www.cnblogs.com/Anker/p/3269106.html 首先明白一个概念: ...

  6. leetCode 72.Edit Distance (编辑距离) 解题思路和方法

    Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert  ...

  7. 去除iframe滚动条1

    主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...

  8. gpg 的使用

    GPG入门教程 GpG使用指南 1. 安装 源码编译安装:源码下载地址 ./configure make make install 直接安装编译好的二进制文件 # Debian / Ubuntu 环境 ...

  9. C语言学习小记

    2013年1月31日 今天试着编程为报文去头去尾.   #include #include #define MAX_LENTH 1024 int main() {  char *path = &quo ...

  10. System.IO.FileLoadException异常

    未能加载文件或程序集“NHibernate, Version=4.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4”或它的某一个依赖 ...