BZOJ 1375 Bicriterial routing 双调路径 (二维最短路)
来源:互联网 发布:php授权验证系统源码 编辑:程序博客网 时间:2024/05/16 04:46
1375: [Baltic2002]Bicriterial routing 双调路径
Time Limit: 5 Sec Memory Limit: 64 MB
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
思路 :
dp[ i ][ j ]代表到第i个点,到i位置,费用为j时的最小用时。
然后spfa跑最短路就好啦。
因为费用不超过一百,所以如果费用比(n-1)*100还要大就break。
#include <cstring>#include <iostream>#include <queue>#include <cstdio>#include <algorithm>#define N 110#define M 310#define INF 0x3f3f3f3fusing namespace std;int n, m, s, t, idc;int ans = 0;int head[N];struct Edge{ int from, to, val, tim, nxt;}ed[M<<1];struct AA{ int pos, val;};int dp[N][N*N], vis[N][N*N];void init(){ memset(head, 0, sizeof(head)); idc = 0;}void adde(int u, int v, int val, int tim){ ed[++idc].from = u; ed[idc].to = v; ed[idc].val = val; ed[idc].tim = tim; ed[idc].nxt = head[u]; head[u] = idc;}void spfa(){ memset(dp, 0x3f, sizeof(dp)); queue <AA> q; AA cc; cc.pos = s, cc.val = 0; q.push( cc ); vis[cc.pos][cc.val] = 1; dp[cc.pos][cc.val] = 0; while( !q.empty() ){ AA u = q.front(); q.pop(); vis[u.pos][u.val] = 0; if(u.val > n*N) continue; for(int i = head[u.pos]; i; i = ed[i].nxt){ int v = ed[i].to; if(dp[v][u.val+ed[i].val] > dp[u.pos][u.val] + ed[i].tim){ dp[v][u.val+ed[i].val] = dp[u.pos][u.val] + ed[i].tim; if( !vis[v][u.val + ed[i].val] ){ vis[v][u.val + ed[i].val] = 1; cc.pos = v, cc.val = u.val + ed[i].val; q.push( cc ); } } } }}int main(){ init(); scanf("%d%d%d%d", &n, &m, &s, &t); for(int i=1; i<=m; i++){ int u, vis, val, tim; scanf("%d%d%d%d", &u, &vis, &val, &tim); adde(u, vis, val, tim), adde(vis, u, val, tim); } spfa(); int mi = INF; for(int i=0; i<=n*N; i++){ if(dp[t][i] == INF || dp[t][i] >= mi) continue; mi = dp[t][i]; ans++; } printf("%d\n", ans); return 0;}
阅读全文
0 0
- BZOJ 1375 Bicriterial routing 双调路径 (二维最短路)
- bzoj1375 [Baltic2002]Bicriterial routing 双调路径 (两个值的最短路)
- 【BZOJ 1375】 [Baltic2002]Bicriterial routing 双调路径
- BZOJ 1375 [Baltic2002]Bicriterial routing 双调路径 SPFA
- BZOJ 1375: [Baltic2002]Bicriterial routing 双调路径 SPFA+DP思想
- bzoj1375[Baltic2002]Bicriterial routing 双调路径
- BZOJ 3889: [Usaco2015 Jan]Cow Routing 双键值最短路
- 最短路(输出路径)
- 【BZOJ】1975 [Sdoi2010]魔法猪学院 k短路(最短路径+A*)
- 【BZOJ】1598 [Usaco2008 Mar]牛跑步 k短路(最短路径+A*)
- hdu 4396(spfs/二维最短路)
- Lightoj 1281 (二维最短路)
- 二维最短路
- 【bzoj3889】[Usaco2015 Jan]Cow Routing 最短路
- hdoj2544_最短路(最短路径)
- 最短路(最短路径)
- HDU2544最短路(最短路径)
- BZOJ 2763 飞行路线(最短路)
- IPC机制系列之三 Android中的IPC方式
- centos安装tomcat
- linux C/C++服务器后台开发面试题总结
- 690. Employee Importance
- GIT中文乱码问题解决方案
- BZOJ 1375 Bicriterial routing 双调路径 (二维最短路)
- 将Android项目上传到Github
- SQL中EXISTS的用法
- 懒人读算法(十一)-找文字
- C#调用OpenCV2.4.9和OpenCV3.0.0
- 基数排序(桶排序)
- Android极光推送区分测试正式环境详解
- IDEA配置github并上传项目
- java多次发送邮件