[CQOI2015]网络吞吐量
Description:
给你一个图,每个点可以被经过\(a_i\)次,求有多少个人可以走最短路到n点
Hint:
\(n \le 500\)
Solution:
极其水的一道题,就当做复习最短路板子了
先跑最短路,然后把满足\(dis[v]=dis[u]+t[i].w\)的点连起来,拆个点就完事了
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
const ll mxn=2e5+5,inf=1e18;
ll S,T,n,m,k,cnt,cnt1,ans,dis[mxn],vis[mxn],hd1[mxn],a[mxn],dep[mxn],cur[mxn],mp[500][500],hd[mxn];
ll dx[9]={1,1,-1,-1,3,3,-3,-3};
ll dy[9]={3,-3,3,-3,1,-1,1,-1};
inline ll read() {
char c=getchar(); ll x=0,f=1;
while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
while(c<='9'&&c>='0') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
return x*f;
}
inline void chkmax(ll &x,ll y) {if(x<y) x=y;}
inline void chkmin(ll &x,ll y) {if(x>y) x=y;}
struct ed {
ll to,nxt,w;
}t[mxn<<1],t1[mxn<<1];
void add1(ll u,ll v,ll w) {
t1[++cnt1]=(ed) {v,hd1[u],w}; hd1[u]=cnt1;
}
inline void add(ll u,ll v,ll w) {
t[cnt]=(ed) {v,hd[u],w}; hd[u]=cnt++;
t[cnt]=(ed) {u,hd[v],0}; hd[v]=cnt++;
}
ll bfs() {
memset(dep,0,sizeof(dep)); queue<ll > q;
q.push(S); dep[S]=1;
for(ll i=0;i<=n*2+1;++i) cur[i]=hd[i];
while(!q.empty()) {
ll u=q.front(); q.pop();
for(ll i=hd[u];i!=-1;i=t[i].nxt) {
ll v=t[i].to;
if(dep[v]==0&&t[i].w>0)
dep[v]=dep[u]+1,q.push(v);
}
}
if(dep[T]==0) return 0;
return 1;
}
ll dfs(ll u,ll f) {
if(u==T) return f;
for(ll &i=cur[u];i!=-1;i=t[i].nxt) {
ll v=t[i].to;
if(dep[v]==dep[u]+1&&t[i].w>0) {
ll tp=dfs(v,min(f,t[i].w));
if(tp>0) {
t[i].w-=tp;
t[i^1].w+=tp;
return tp;
}
}
}
return 0;
}
void Dinic() {
while(bfs())
while(ll tp=dfs(S,inf))
{ans+=tp;}
}
ll get(ll x,ll y) {
return (x-1)*m+y;
}
priority_queue<pair<ll ,ll > > q;
void Dij() {
q.push(make_pair(0,1)); memset(dis,0x3f,sizeof(dis));
dis[1]=0;
while(!q.empty()) {
ll u=q.top().second; q.pop();
if(vis[u]) continue ;
for(ll i=hd1[u];i;i=t1[i].nxt) {
ll v=t1[i].to;
if(vis[v]) continue ;
if(dis[v]>dis[u]+t1[i].w) {
dis[v]=dis[u]+t1[i].w;
q.push(make_pair(-dis[v],v));
}
}
}
}
void init() {
for(ll i=1;i<=n;++i) {
for(ll j=hd1[i];j;j=t1[j].nxt) {
ll v=t1[j].to;
if(dis[v]==dis[i]+t1[j].w) add(i+n,v,inf);
}
}
}
int main()
{
memset(hd,-1,sizeof(hd)); ll u,v,w;
n=read(); m=read(); T=2*n+1; add(S,1,inf); add(1,n+1,inf); add(n,n+n,inf); add(n+n,T,inf);
for(ll i=1;i<=m;++i) {
u=read(); v=read(); w=read();
add1(u,v,w); add1(v,u,w);
}
a[1]=read();
for(ll i=2;i<n;++i) a[i]=read(),add(i,i+n,a[i]);
a[n]=read();
Dij(); init(); Dinic();
printf("%lld",ans);
return 0;
}
[CQOI2015]网络吞吐量的更多相关文章
- BZOJ 3931: [CQOI2015]网络吞吐量
3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1555 Solved: 637[Submit][Stat ...
- bzoj3931: [CQOI2015]网络吞吐量
将最短路图找出来,跑maxflow即可.有注意到数据范围.然后输出的时候%dWA了三次QAQ... #include<cstdio> #include<cstring> #in ...
- BZOJ 3931: [CQOI2015]网络吞吐量 最大流
3931: [CQOI2015]网络吞吐量 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- BZOJ 3931: [CQOI2015]网络吞吐量( 最短路 + 最大流 )
最短路 + 最大流 , 没什么好说的... 因为long long WA 了两次.... ------------------------------------------------------- ...
- 3931: [CQOI2015]网络吞吐量
3931: [CQOI2015]网络吞吐量 链接 分析: 跑一遍dijkstra,加入可以存在于最短路中的点,拆点最大流. 代码: #include<cstdio> #include< ...
- 洛谷 P3171 [CQOI2015]网络吞吐量 解题报告
P3171 [CQOI2015]网络吞吐量 题目描述 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最 ...
- bzoj千题计划136:bzoj3931: [CQOI2015]网络吞吐量
http://www.lydsy.com/JudgeOnline/problem.php?id=3931 在最短路网络上跑最大流 #include<queue> #include<c ...
- bzoj 3931: [CQOI2015]网络吞吐量 -- 最短路+网络流
3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec Memory Limit: 512 MB Description 路由是指通过计算机网络把信息从源地址传输到目的地址 ...
- 【BZOJ3931】[CQOI2015]网络吞吐量 最大流
[BZOJ3931][CQOI2015]网络吞吐量 Description 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为 ...
- bzoj3931: [CQOI2015]网络吞吐量(spfa+网络流)
3931: [CQOI2015]网络吞吐量 题目:传送门 题解: 现在有点难受....跳了一个多钟...菜啊... 题意都把做法一起给了....最短路+网路流啊. 不想说话...记得开long lon ...
随机推荐
- 测试框架httpclent 3.获取cookie的信息,然后带cookies去发送请求
在properties文件里面: startupWithCookies.json [ { "description":"这是一个会返回cookies信息的get请求&qu ...
- 第二章 python的介绍及变量
1.编程语言的介绍 a.机器语言 使用二进制编写指令的编程方式 b.汇编语言 汇编指令与机器语言相对应 c.高级语言 需要借助特殊的工具将其转换成机器语言,但是方便人进行阅读理解的编程方式 从执行效率 ...
- 集成Tomcat环境到Eclipse中
集成Tomcat环境到Eclipse中 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装Eclipse环境 1>.安装JDK环境 官方地址:https://www.or ...
- solr的基础和安装
下载地址 http://archive.apache.org/dist/lucene/solr/ 推荐 http://www.apache.org/dyn/closer.lua/lucene/so ...
- 14、使用csv和excel存储豆瓣top250电影信息
记得我们第三关的时候爬取了豆瓣TOP250的电影名/评分/推荐语/链接,现在呢,我们要把它们存储下来,记得用今天课上学的csv和excel,分别存储下来哦- URL htt ...
- [物理学与PDEs]第3章第2节 磁流体力学方程组 2.3 磁流体力学方程组
1. 磁流体力学方程组 $$\beex \bea \cfrac{\p {\bf H}}{\p t} &-\rot({\bf u}\times{\bf H})=\cfrac{1}{\sigma ...
- Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)
题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...
- python Flask web框架
目录: --> Flask --> 配置文件 --> 配置文件解析 --> 配置文件导入 --> 路由 --> 路由参数 --> 常用路由匹配 --> ...
- php7 + 新特性 部分
三目运算符: 以前:$type = isset($_GET['type']) ? $_GET['type'] : '测试'; php7.0: $type = $_GET['type'] ?? '测试' ...
- how2heap学习笔记
github源代码地址 这里只分析glibc2.25堆分配的特性,为了方便调试编译时使用 gcc -g -no-pie <input_file_name> -o <output_fi ...