调了两天的代码,到最后绝望地把I64d改成lld就过了,我真的是醉了。

网络吞吐量

题面:给出一张(n个点,m条边)带权(点权边权均有)无向图,点权为每个点每秒可以接受发送的最大值,边权为花费,保证数据沿着最短路径从1发送到n。

题解:因为保证数据沿着最短路发送,所以可以求出1到n的最短路,然后将符合最短路的边全部加到网络图(一定是符合条件的所有边,而非最短路上的边,因为最短路长度唯一,而路径不唯一,故点权不唯一,所以应该将所有符合条件的边都加入),这些边的容量为INF,因为流量限制在点上,所以最短路边权不限制流量,限制工作交给点来完成。将一个点拆成入点和出点,入点到出点的边权为点权以达到限流作用,最后跑一次最大流即为所求。

PS:这题是CQOI2015的题,不得不说这题作为专题的A是有道理的,因为是最短路+网络流拆点的模板,比较和谐。~鬼知道I64d会WA???~除此,还了解到了SPFA的两个小优化(SLF,LLL),可以说收获不小。~ISAP是真滴好写~


#pragma comment(linkerr, "/STACK: 1024000000,1024000000")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pii pair<int,int>
#define de(x) cout << #x << " = " << x << endl
#define clr(a,b) memset(a,b,sizeof(a))
#define INF (0x3f3f3f3f)
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))
#define F first
#define S second
using namespace std; const int N = 5006;
const int M = 1e5 + 15;
typedef long long ll;
typedef pair<ll, int> pli;
struct Edge
{
int u, v, nxt;
ll w;
};
Edge e1[M<<2], e2[M<<2];
int h1[N<<2], h2[N<<2], ect1, ect2;
ll dis[N<<2];
int d[N<<2], gap[N<<2], cur[N<<2];
bool vis[N<<2];
int n, m, ct;
int a[M], b[M];
ll c[M];
ll val[N]; void init()
{
clr(vis,0);
clr(h1,-1); clr(h2,-1);
ect1 = ect2 = 0;
}
void _add1( int u, int v, ll w )
{
e1[ect1].u = u;
e1[ect1].v = v;
e1[ect1].nxt = h1[u];
e1[ect1].w = w;
h1[u] = ect1++;
}
void _add2( int u, int v, ll w )
{
e2[ect2].u = u;
e2[ect2].v = v;
e2[ect2].nxt = h2[u];
e2[ect2].w = w;
h2[u] = ect2++;
} void dij( int s, int t )
{
for ( int i = 1; i <= n; i ++ )
dis[i] = LINF;
dis[t] = 0;
priority_queue<pli> q;
q.push( {0ll,t} );
while ( !q.empty() )
{
pli nw = q.top(); q.pop();
int u = nw.S;
if ( vis[u] ) continue;
vis[u] = 1;
for ( int i = h1[u]; i+1; i = e1[i].nxt )
{
int v = e1[i].v;
if ( dis[v] > dis[u] + e1[i].w )
{
dis[v] = dis[u] + e1[i].w;
q.push( {-dis[v], v} );
}
}
}
} void bfs( int s, int t )
{
queue<int> q;
clr(d,0); clr(gap,0);
++gap[d[t] = 1];
ct = 1;
q.push(t);
while ( !q.empty() )
{
int u = q.front(); q.pop();
for ( int i = h2[u]; i+1; i = e2[i].nxt )
{
int v = e2[i].v;
if ( d[v] ) continue;
++gap[d[v] = d[u]+1];
q.push(v);
ct ++;
}
}
} ll aug( int u, int s, int t, ll mi )
{
if ( u == t ) return mi;
ll flw = 0;
for ( int &i = cur[u]; i+1; i = e2[i].nxt )
{
int v = e2[i].v;
if ( d[u] == d[v] + 1 )
{
ll tp = aug( v, s, t, min(mi,e2[i].w) );
flw += tp, mi -= tp, e2[i].w -= tp, e2[i^1].w += tp;
if ( !mi ) return flw;
}
}
if ( !(--gap[d[u]]) ) d[s] = ct+1;
++gap[++d[u]], cur[u] = h2[u];
return flw;
} ll mxflw( int s, int t )
{
bfs(s,t);
for ( int i = 1; i <= 2*n; i ++ )
cur[i] = h2[i];
ll res = aug( s, s, t, LINF );
while ( d[s] <= ct )
res += aug( s, s, t, LINF );
return res;
} void build( int s, int t )
{
queue<int> q;
q.push(s);
clr(vis,0);
vis[s] = 1;
while ( !q.empty() )
{
int u = q.front(); q.pop();
for ( int i = h1[u]; i+1; i = e1[i].nxt )
{
int v = e1[i].v;
if ( dis[u] == dis[v] + e1[i].w )
{
_add2( u+n, v, LINF ), _add2( v, u+n, 0ll );
if ( !vis[v] ) q.push(v), vis[v] = 1;
}
}
}
} int main()
{
init();
scanf("%d%d", &n, &m);
for ( int i = 0; i < m; i ++ )
{
scanf("%d%d%lld", &a[i], &b[i], &c[i]);
_add1(a[i],b[i],c[i]); _add1(b[i],a[i],c[i]);
}
dij(1,n);
build(1,n); for ( int i = 1; i <= n; i ++ )
scanf("%lld", &val[i]);
for ( int i = 2; i < n; i ++ )
{
_add2( i, i+n, val[i]);
_add2( i+n, i, 0ll );
}
int S = 1, T = n;
_add2( 1, 1+n, LINF ); _add2( 1+n, 1, 0ll ); ll mx = mxflw( S, T );
printf("%lld\n", mx);
return 0;
} /*
3 2
1 2 1
2 3 1
1
2
3
*/

G_M_网络流A_网络吞吐量的更多相关文章

  1. 【BZOJ3931】【CQOI2015】网络吞吐量(最短路,网络流)

    [BZOJ3931][CQOI2015]网络吞吐量(最短路,网络流) 题面 跑到BZOJ上去看把 题解 网络流模板题??? SPFA跑出最短路,重新建边后 直接Dinic就行了 大火题嗷... #in ...

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

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

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

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

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

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

  5. 网络流(最大流) CQOI 2015 BZOJ 3931 网络吞吐量

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

  6. bzoj3931: [CQOI2015]网络吞吐量(spfa+网络流)

    3931: [CQOI2015]网络吞吐量 题目:传送门 题解: 现在有点难受....跳了一个多钟...菜啊... 题意都把做法一起给了....最短路+网路流啊. 不想说话...记得开long lon ...

  7. BZOJ 3931: [CQOI2015]网络吞吐量

    3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1555  Solved: 637[Submit][Stat ...

  8. 【BZOJ-3931】网络吞吐量 最短路 + 最大流

    3931: [CQOI2015]网络吞吐量 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1228  Solved: 524[Submit][Stat ...

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

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

随机推荐

  1. c# WinForm 边框阴影窗体

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. 电力项目十七--数据字典首页JS添加和删除表格

    知识点:jQuery是一个JavaScript函数库. JS代码: function insertRows(){ //获取表格对象 var tb1 = $("#dictTbl"); ...

  3. spfile与pfile

    SYS@ora11g>show parameter spfile NAME TYPE------------------------------------ ------------------ ...

  4. 几何+点与线段的位置关系+二分(POJ2318)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10666   Accepted: 5128 Description ...

  5. KMP的next数组性质运用

    hdu2594 Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  6. java实现创建临时文件然后在程序退出时自动删除文件(转)

    这篇文章主要介绍了java实现创建临时文件然后在程序退出时自动删除文件,从个人项目中提取出来的,小伙伴们可以直接拿走使用. 通过java的File类创建临时文件,然后在程序退出时自动删除临时文件.下面 ...

  7. spring-boot集成redis

    application.properties #redis 配置 # Redis数据库索引(默认为0) spring.redis.database=0 # Redis服务器地址 spring.redi ...

  8. CSS Spritec下载,精灵图,雪碧图,初探之原理、使用

    CSS Spritec下载,精灵图,雪碧图,初探之原理.使用 关于CSS Sprite CSSSprites在国内很多人叫css精灵雪碧图,是一种网页图片应用处理方式.它允许你将一个页面涉及到的所有零 ...

  9. ubuntu16.04下安装opencv-nonfree

    在写计算机视觉与导航技术的课程作业,是关于sift和surf特征的提取及匹配.因为opencv中都有直接的函数可以调用. 关于SIFT和SURF的特征在opencv的nonfree模块中,从字面意思就 ...

  10. sosi-statistics

    set echo offset scan onset lines 150set pages 66set verify offset feedback offset termout offcolumn ...