BZOJ 3931: [CQOI2015]网络吞吐量 最大流
3931: [CQOI2015]网络吞吐量
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=3931
Description
Input
Output
Sample Input
7 10
1 2 2
1 5 2
2 4 1
2 3 3
3 7 1
4 5 4
4 3 1
4 6 1
5 6 2
6 7 1
1
100
20
50
20
60
1
Sample Output
HINT
题意
题解:
跑最短路之后拆点,拆点来维护每个点最大扔出去的网络吞吐量
然后直接搞就好了……
这道题要爆int = =!
怒wa一发
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 110000
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const ll Inf=0x3f3f3f3f3f3f3f3fll;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//**************************************************************************************
namespace NetFlow
{
const ll MAXN=,MAXM=,inf=0x3f3f3f3f3f3f3f3fll;
struct Edge
{
ll v,c,f,nx;
Edge() {}
Edge(ll v,ll c,ll f,ll nx):v(v),c(c),f(f),nx(nx) {}
} E[MAXM];
ll G[MAXN],cur[MAXN],pre[MAXN],dis[MAXN],gap[MAXN],N,sz;
void init(ll _n)
{
N=_n,sz=; memset(G,-,sizeof(G[])*N);
}
void link(ll u,ll v,ll c)
{
E[sz]=Edge(v,c,,G[u]); G[u]=sz++;
E[sz]=Edge(u,,,G[v]); G[v]=sz++;
}
bool bfs(int S,int T)
{
static int Q[MAXN]; memset(dis,-,sizeof(dis[])*N);
dis[S]=; Q[]=S;
for (int h=,t=,u,v,it;h<t;++h)
{
for (u=Q[h],it=G[u];~it;it=E[it].nx)
{
if (dis[v=E[it].v]==-&&E[it].c>E[it].f)
{
dis[v]=dis[u]+; Q[t++]=v;
}
}
}
return dis[T]!=-;
}
ll dfs(ll u,ll T,ll low)
{
if (u==T) return low;
ll ret=,tmp,v;
for (ll &it=cur[u];~it&&ret<low;it=E[it].nx)
{
if (dis[v=E[it].v]==dis[u]+&&E[it].c>E[it].f)
{
if (tmp=dfs(v,T,min(low-ret,E[it].c-E[it].f)))
{
ret+=tmp; E[it].f+=tmp; E[it^].f-=tmp;
}
}
}
if (!ret) dis[u]=-; return ret;
}
ll dinic(int S,int T)
{
ll maxflow=,tmp;
while (bfs(S,T))
{
memcpy(cur,G,sizeof(G[])*N);
while (tmp=dfs(S,T,inf)) maxflow+=tmp;
}
return maxflow;
}
}
using namespace NetFlow; int n,m;
struct node
{
ll x,y;
};
vector<node> EE[maxn];
ll d[maxn];
ll inq[maxn];
ll cost[maxn];
struct EEdge
{
ll x,y,z;
};
EEdge edge[maxn];
vector<ll> U,V;
int main()
{
n=read(),m=read();
for(int i=;i<=m;i++)
{
edge[i].x=read(),edge[i].y=read(),edge[i].z=read();
EE[edge[i].x].push_back((node){edge[i].y,edge[i].z});
EE[edge[i].y].push_back((node){edge[i].x,edge[i].z});
}
for(int i=;i<=n;i++)
d[i]=Inf;
queue<int> Q;
Q.push();
d[]=;
inq[]=;
while(!Q.empty())
{
int u = Q.front();
Q.pop();
inq[u]=;
for(int i=;i<EE[u].size();i++)
{
node v = EE[u][i];
if(v.y+d[u]<d[v.x])
{
d[v.x]=v.y+d[u];
if(!inq[v.x])
{
Q.push(v.x);
inq[v.x]=;
}
}
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<EE[i].size();j++)
{
node v = EE[i][j];
if(d[i]+v.y==d[v.x])
U.push_back(i+n),V.push_back(v.x);
}
}
init();
for(int i=;i<=n;i++)
{
cost[i]=read();
if(i!=&&i!=n)
link(i,i+n,cost[i]);
else
link(i,i+n,inf);
}
for(int i=;i<V.size();i++)
link(U[i],V[i],inf);
printf("%lld\n",dinic(,*n));
}
BZOJ 3931: [CQOI2015]网络吞吐量 最大流的更多相关文章
- BZOJ 3931: [CQOI2015]网络吞吐量( 最短路 + 最大流 )
最短路 + 最大流 , 没什么好说的... 因为long long WA 了两次.... ------------------------------------------------------- ...
- BZOJ 3931: [CQOI2015]网络吞吐量
3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1555 Solved: 637[Submit][Stat ...
- bzoj 3931: [CQOI2015]网络吞吐量 -- 最短路+网络流
3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec Memory Limit: 512 MB Description 路由是指通过计算机网络把信息从源地址传输到目的地址 ...
- bzoj 3931 [CQOI2015]网络吞吐量(最短路,最大流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3931 [题意] 只能通过1-n的最短路,求网络最大流 [思路] 分别以1,n为起点做最 ...
- BZOJ 3931 [CQOI2015]网络吞吐量:最大流【拆点】
传送门 题意 给你一个 $ n $ 个点,$ m $ 条边的无向网络,每条边有长度.每个点的流量限制为 $ c[i] $ . 要求流量只能经过从 $ 1 $ 的 $ n $ 的最短路.问你最大流是多少 ...
- BZOJ 3931: [CQOI2015]网络吞吐量 Dijkstra+最大流
这个没啥难的. 只保留可以转移最短路的边,然后拆点跑一个最大流即可. #include <bits/stdc++.h> #define N 1004 #define M 250004 #d ...
- ●BZOJ 3931 [CQOI2015]网络吞吐量
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3931 题解: 在最短路图上跑网络流,要开long long(无奈 BZOJ AC 不了,洛谷 ...
- 3931: [CQOI2015]网络吞吐量
3931: [CQOI2015]网络吞吐量 链接 分析: 跑一遍dijkstra,加入可以存在于最短路中的点,拆点最大流. 代码: #include<cstdio> #include< ...
- 【BZOJ3931】[CQOI2015]网络吞吐量 最大流
[BZOJ3931][CQOI2015]网络吞吐量 Description 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为 ...
随机推荐
- GitHub上README.md教程
最近对它的README.md文件颇为感兴趣.便写下这贴,帮助更多的还不会编写README文件的同学们. README文件后缀名为md.md是markdown的缩写,markdown是一种编辑博客的语言 ...
- SQL2012远程连接到SQL2008时的问题:已成功与服务器建立连接,但在登陆过程中发生错误。
服务器装的是2008,我机上装的是2012,结果一远程连接马上报错而且2012直接crash了.后来找到这位兄弟的帖子,http://www.cnblogs.com/liuguozhu2015/p/3 ...
- java web 学习四(http协议)
一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...
- Jedis的Sharded源代码分析
概述 Jedis是Redis官方推荐的Java客户端,更多Redis的客户端可以参考Redis官网客户端列表.当业务的数据量非常庞大时,需要考虑将数据存储到多个缓存节点上,如何定位数据应该存储的节点, ...
- 基于GPL329xx linux平台电容屏gsl1680的驱动调试分析
因客户有用到了gsl1680 7寸电容屏,所以拿了一块过来,便在329xx的平台上面开始调试了. 大概浏览了一下所提供的资料,只有介绍模组的资料跟一份中文版的datasheet,datasheet只是 ...
- C#冒泡排序详解
今天写一简单的冒泡排序,带有详细的中文注释,新手一定要看看! 因为这是找工作面试时经常 笔试 要考的题目. using System; using System.Collections.Generic ...
- HDU5778 abs
http://acm.hdu.edu.cn/showproblem.php?pid=5778 思路:只有平方质因子的数,也就是这题所说的 y的质因数分解式中每个质因数均恰好出现2次 满足条件的数 ...
- POJ 1004 解题报告
1.题目描述: http://poj.org/problem?id=1004 2.解题过程 这个题目咋一看很简单,虽然最终要解出来的确也不难,但是还是稍微有些小把戏在里面,其中最大的把戏就是float ...
- JAVA基础----java中E,T,?的区别
遇到<A>,<B>,<K,V>等,是用到了java中的泛型. 一般使用<T>来声明类型持有者名称,自定义泛型类时,类持有者名称可以使用T(Type) 如 ...
- 无奈卸载Clover 转投TotalCommand
Clover 是个好的多Tab 资源管理器,但在Win8下总是崩溃啊,让人很崩溃. 无奈投奔TotalCommand吧,就是梯度有些高. 当然不习惯,也可以使用下 XYPlorer