BZOJ 1375: [Baltic2002]Bicriterial routing 双调路径 SPFA+DP思想
来源:互联网 发布:中国实体经济数据2017 编辑:程序博客网 时间:2024/05/16 11:10
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 513 Solved: 189
Description
来越多,因此选择最佳路径是很现实的问题。城市的道路是双向的,每条道路有固定的旅行时间以及需要支付的费用。路径由连续的道路组成。总时间是各条道路旅行时间的和,总费用是各条道路所支付费用的总和。同样的出发地和目的地,如果路径A比路径B所需时间少且费用低,那么我们说路径A比路径B好。对于某条路径,如果没有其他路径比它好,那么该路径被称为最优双调路径。这样的路径可能不止一条,或者说根本不存在。 给出城市交通网的描述信息,起始点和终点城市,求最优双条路径的条数。城市不超过100个,边数不超过300,每条边上的费用和时间都不超过100。
Input
第一行给出有多少个点,多少条边,开始点及结束点. 下面的数据用于描述这个地图
Output
有多少条最优双调路径
Sample Input
4 5 1 4
2 1 2 1
3 4 3 1
2 3 1 2
3 1 1 4
2 4 2 4
Sample Output
2
HINT
Source
因为要满足条件的话,必须要在两个值中有个值是所有值中最小的,或者说满足大于某个值的其他组的另一个值都小于他,那么我们就可以搞一个DP数组,dp[i][j]表示从起点开始走到i点,花费时间最少为j的时候道路费用最少为dp[i][j],然后最后我们for一遍就可以了,因为dp[T][i]中,for的时候i是具有单调性的
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<queue>using namespace std;const int MAXN = 106;const int MAXM = 606;const int up = 10000;int n, m, head[MAXN], tail, dis[MAXN][ MAXN * MAXN ], inf, S, T;struct Line{ int to, nxt, flow, tim; }line[ MAXM * 2 ];bool vis[MAXN][ MAXN * MAXN ];void add_line( int from, int to, int flow, int tim ) { line[++tail].nxt = head[from]; line[tail].to = to; line[tail].tim = tim; line[tail].flow = flow; head[from] = tail;}queue<pair<int,int> > q;void SPFA( ) { memset( dis, 0x3f, sizeof( dis ) ); memset( vis, false, sizeof( vis ) ); inf = dis[0][0]; q.push( make_pair( S, 0 ) ); dis[S][0] = 0; vis[S][0] = true; while( !q.empty() ) { pair< int, int > tmp = q.front(); q.pop(); int u = tmp.first; int flowu = tmp.second; vis[u][flowu] = false; for( register int i = head[u]; i; i = line[i].nxt ) { int v = line[i].to; int flowv = flowu + line[i].flow; if( flowv <= up ) { if( dis[v][flowv] > dis[u][flowu] + line[i].tim ) { dis[v][flowv] = dis[u][flowu] + line[i].tim; if( vis[v][flowv] ) continue; q.push( make_pair( v, flowv ) ); vis[v][flowv] = true; } } } }}int main( ) { scanf( "%d%d%d%d", &n, &m, &S, &T ); for( register int i = 1; i <= m; i++ ) { int ff, tt, ww, ti; scanf( "%d%d%d%d", &ff, &tt, &ww, &ti ); add_line( ff, tt, ww, ti ); add_line( tt, ff, ww, ti ); } SPFA(); int minn = inf; int cnt = 0; for( register int i = 0; i <= up; i++ ) { if( dis[T][i] < minn ) { minn = dis[T][i]; cnt++; } } printf( "%d\n", cnt ); return 0;}
阅读全文
0 0
- BZOJ 1375: [Baltic2002]Bicriterial routing 双调路径 SPFA+DP思想
- BZOJ 1375 [Baltic2002]Bicriterial routing 双调路径 SPFA
- 【BZOJ 1375】 [Baltic2002]Bicriterial routing 双调路径
- bzoj1375[Baltic2002]Bicriterial routing 双调路径
- bzoj1375 [Baltic2002]Bicriterial routing 双调路径 (两个值的最短路)
- BZOJ 1375 Bicriterial routing 双调路径 (二维最短路)
- bzoj 3889: [Usaco2015 Jan]Cow Routing SPFA
- bzoj 1003(spfa+dp)
- BZOJ 1003 SPFA + DP
- bzoj 1003 dp+spfa
- [BZOJ 1003] 物流运输 SPFA+DP
- BZOJ 3875 - SPFA处理带环的DP
- BZOJ-1003 物流运输trans SPFA+DP
- BZOJ 1003: [ZJOI2006]物流运输(spfa+dp)
- BZOJ 1003 物流运输(Spfa+dp)
- bzoj 1003 物流运输 DP+Spfa
- 【BZOJ 1003】[ZJOI2006]物流运输 【SPFA+DP】
- bzoj 1003: [ZJOI2006]物流运输(spfa+dp)
- Nginx下无法使用中文URL的解决方法
- C++动态内存
- [C# 网络编程系列]专题三:自定义Web服务器
- Swarm的进化和在阿里的大规模应用实践
- Ubuntu Server 14.04升级Ubuntu Server 16.04
- BZOJ 1375: [Baltic2002]Bicriterial routing 双调路径 SPFA+DP思想
- 实习日志(第七周)
- 精通闭包(自用)
- 安卓圆形头像理解
- Tensorflow 指定GPU运行
- PHP7.1安装yaf扩展
- 【性能测试菜鸟】收集各路大神的各种信息
- db2客户端用dbvisualizer无法进行reorg操作
- maven配置阿里云镜像