BZOJ 1375: [Baltic2002]Bicriterial routing 双调路径 SPFA+DP思想
2017-10-13 10:13
363 查看
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 513 Solved: 189
2 1 2 1
3 4 3 1
2 3 1 2
3 1 1 4
2 4 2 4
HINT
Submit: 513 Solved: 189
Description
来越多,因此选择最佳路径是很现实的问题。城市的道路是双向的,每条道路有固定的旅行时间以及需要支付的费用。路径由连续的道路组成。总时间是各条道路旅行时间的和,总费用是各条道路所支付费用的总和。同样的出发地和目的地,如果路径A比路径B所需时间少且费用低,那么我们说路径A比路径B好。对于某条路径,如果没有其他路径比它好,那么该路径被称为最优双调路径。这样的路径可能不止一条,或者说根本不存在。 给出城市交通网的描述信息,起始点和终点城市,求最优双条路径的条数。城市不超过100个,边数不超过300,每条边上的费用和时间都不超过100。Input
第一行给出有多少个点,多少条边,开始点及结束点. 下面的数据用于描述这个地图Output
有多少条最优双调路径Sample Input
4 5 1 42 1 2 1
3 4 3 1
2 3 1 2
3 1 1 4
2 4 2 4
Sample Output
2HINT
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; }
相关文章推荐
- BZOJ 1375 [Baltic2002]Bicriterial routing 双调路径 SPFA
- bzoj1375 [Baltic2002]Bicriterial routing 双调路径 (两个值的最短路)
- bzoj1375[Baltic2002]Bicriterial routing 双调路径
- 【BZOJ 1375】 [Baltic2002]Bicriterial routing 双调路径
- BZOJ 1375 Bicriterial routing 双调路径 (二维最短路)
- bzoj1375 双调路径
- [BZOJ 1907] 树的路径覆盖 【树形DP】
- bzoj 3889: [Usaco2015 Jan]Cow Routing SPFA
- BZOJ 1097 [POI 2007] SPFA+状压DP 解题报告
- 【概率DP/高斯消元】BZOJ 2337:[HNOI2011]XOR和路径
- BZOJ 2150 浅谈二分图Bipartite Graph及DAG最小路径覆盖
- 【ZJOI2017 Round1练习&UVA1057】D6T1 Routing(DP,SPFA)
- bzoj 1003 dp+spfa
- bzoj 2337 [HNOI2011]XOR和路径【高斯消元+dp】
- NOIP2002-过河卒—经典的dp思想
- BZOJ4720 [Noip2016]换教室 解题报告【SPFA】【期望DP】
- Codeforces 507E Breaking Good【最短路SPFA+Dp+记录路径】好题~~~
- 【bzoj3875】【AHOI2014】【骑士游戏】【spfa+dp】
- bzoj 1003: [ZJOI2006]物流运输(spfa+dp)
- BZOJ 1003 物流运输【dp+最短路SPFA】好题!