题意:
给定起点(xs,ys),
终点(xd,yd),
最大旅程距离B
汽车的每公里代价C0
其余交通方式数量T<=100
其余交通方式代价[C1…CT]<=100
车站数量N<=1000
第i个车站的位置(xi,yi),边数li<=100,每条边(j,mj)表示连向第j个车站,交通方式为mj
可以开车从s到任一车站或目的地,从任一车站开车到目的地,但是车站间不得开车
问在旅程B内的最小代价
简化:无向图,起点s,终点t,边(u,v,a,b),要求s->t的路径边权b<=B条件下,边权a最小
直接用二维dij算法,d[u][j]表示到点u,累计路程b==j情况下代价w的最小值
思路:首先这题给出的数据比较复杂,用链式前向星建图时间效率更优。
每条边存公里数b,代价w。
于是问题简化成,在一个有双重边权的图里面,求出出发点到终点的最短路程(代价w最小),且另一个的权重积累不能超过B
//二维迪杰斯特拉算法问题,把dist数组以及vis数组改成2维 优先队列的节点改成3维即可
注意数据大小maxn要2e5 ,因为边数可能达到2e5
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<unordered_map>
#include<math.h>
#include<set>
using namespace std;
#define INF 0x3f3f3f
#define LL long long
const int maxn=2e5+5;
struct
{
int x,y;
}p[maxn];//点坐标
struct Node
{
int u,tw,tb;//顶点信息 ,i到u的最优co2tw,对应的公里数tb
friend bool operator < (const Node &a,const Node &b)
{
if(a.tw!=b.tw) return a.tw>b.tw;
else return a.tb>b.tb;
}
};//优先队列节点 w小的优先
struct node
{
int to;
int w,b;//w是co2排放量 b是公里数
int next;
}edge[maxn];//链式前向星建图,优化时间
int head[maxn];