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 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为 ...
随机推荐
- 面试书上一些题目的整理:O(n)复杂度排序年龄 & 青蛙跳台阶
可以按照年龄的个数,设置99个桶,然后桶内处理. 青蛙跳台阶,每次1阶或者2阶,就是fib数 如果每次1到n阶,那么归纳法可得,是2^(n-1) 另外1*2 覆盖 2*n个矩阵的问题,仍然是Fib数. ...
- git batch
git batch 不用每次自己写了:不是特别推荐哦: git add . git commit -m "commit" git push git status
- shell文本过滤编程(一):grep和正則表達式
[版权声明:转载请保留出处:blog.csdn.net/gentleliu.Mail:shallnew at 163 dot com] Linux系统中有非常多文件,比方配置文件.日志文件.用户文件等 ...
- ICMP 隧道——将流量封装进 IMCP 的 ping 数据包中,旨在利用 ping 穿透防火墙的检测
利用 ICMP 隧道穿透防火墙 转自:http://xiaix.me/li-yong-icmp-sui-dao-chuan-tou-fang-huo-qiang/ 以前穿透防火墙总是使用 SSH 隧道 ...
- nyoj--18--The Triangle(dp水题)
The Triangle 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...
- CxImage内存方式转换图像
最近,处于项目需要,需要将Bmp转换为JPEG格式.以前做过,采用的是GDI+的方式,该方式有一个极大地缺陷为无法实现跨平台处理.闲话少说,进入正题. CxImage cxImageBmp(pRGBB ...
- 新手村,学会做人选数 https://www.luogu.org/problemnew/show/P1036
#include<cstdio> #include<cmath> #include<string.h> using namespace std; int n,k,s ...
- Mysql实战45讲 06讲全局锁和表锁:给表加个字段怎么有这么多阻碍 极客时间 读书笔记
Mysql实战45讲 极客时间 读书笔记 Mysql实战45讲 极客时间 读书笔记 笔记体会: 根据加锁范围:MySQL里面的锁可以分为:全局锁.表级锁.行级锁 一.全局锁:对整个数据库实例加锁.My ...
- MetaSploit攻击实例讲解------攻击445端口漏洞(kali linux 2016.2(rolling))(详细)
不多说,直接上干货! 大家,相信最近的这个事件,对于445端口已经是非常的小心了.勒索病毒 445端口是一个毁誉参半的端口,有了它我们可以在局域网中轻松访问各种共享文件夹或共享打印机,但也正是因为有了 ...
- Swift学习笔记(9):枚举
目录: 基本语法 关联值 原始值 枚举为一组相关的值定义了一个共同的类型. ・可以给枚举成员指定原始值类型:字符串,字符,整型值或浮点数等 ・枚举成员可以指定任意类型的关联值存储到枚举成员中 ・枚举可 ...