1. 程式人生 > >Bicriterial routing 雙調路徑 HYSBZ - 1375(分層最短路)

Bicriterial routing 雙調路徑 HYSBZ - 1375(分層最短路)

truct man spf ica courier blue led font ont

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

技術分享圖片

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#define inf 0x3f3f3f3f
#define maxc (n-1)*100
using
namespace std; struct edge { int y,ne,c,t; }e[1000]; struct now { int p,c; }; int tot=0,n,m; struct data { int t,f; }d[105][10005]; int s,t,h[105],inq[105][10005]; void Addedge(int x,int y,int co,int ti) { tot++; e[tot].y=y; e[tot].ne=h[x]; h[x]=tot; e[tot].c=co; e[tot].t=ti; }
void spfa() { for (int i=1;i<=n;i++) for (int j=0;j<=maxc;j++) d[i][j].f=0,inq[i][j]=0,d[i][j].t=inf; queue<now> q; now x; x.p=s,x.c=0; d[s][0].f=1,d[s][0].t=0; inq[s][0]=1; q.push(x); while (!q.empty()) { x=q.front(); q.pop(); inq[x.p][x.c]=0; for (int i=h[x.p];i;i=e[i].ne) { int y=e[i].y; int co=e[i].c+x.c; if (co>maxc) continue; if (d[y][co].t>d[x.p][x.c].t+e[i].t) { d[y][co].t=d[x.p][x.c].t+e[i].t; d[y][co].f=1; if (!inq[y][co]) { now aa; aa.p=y,aa.c=co; q.push(aa),inq[y][co]=1; } } } } } int main() { scanf("%d%d%d%d",&n,&m,&s,&t); for (int i=1;i<=m;i++) { int x,y,ti,co; scanf("%d%d%d%d",&x,&y,&co,&ti); Addedge(x,y,co,ti); Addedge(y,x,co,ti); } spfa(); int ans=0,minn=maxc+10; for (int i=0;i<=maxc;i++) { if (!d[t][i].f) continue; if (d[t][i].t>=minn) continue; minn=d[t][i].t; ans++; } cout<<ans<<endl; return 0; }

來越多,因此選擇最佳路徑是很現實的問題。城市的道路是雙向的,每條道路有固定的旅行時間以及需要支付的費用。路徑由連續的道路組成。總時間是各條道路旅行時間的和,總費用是各條道路所支付費用的總和。同樣的出發地和目的地,如果路徑A比路徑B所需時間少且費用低,那麽我們說路徑A比路徑B好。對於某條路徑,如果沒有其他路徑比它好,那麽該路徑被稱為最優雙調路徑。這樣的路徑可能不止一條,或者說根本不存在。 給出城市交通網的描述信息,起始點和終點城市,求最優雙條路徑的條數。城市不超過100個,邊數不超過300,每條邊上的費用和時間都不超過100。Input第一行給出有多少個點,多少條邊,開始點及結束點. 下面的數據用於描述這個地圖Output有多少條最優雙調路徑Sample Input4 5 1 4 2 1 2 1 3 4 3 1 2 3 1 2 3 1 1 4 2 4 2 4

Sample Output2Hint

Bicriterial routing 雙調路徑 HYSBZ - 1375(分層最短路)