题意:给出n个点,m条边,求1到n的最短距离的路径.
题解:,大数据,不可使用Dijkstra邻接矩阵和邻接表,都卡空间和时间,直接上堆优化的最短路模板即可~
代码如下:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int maxn = 1e5 + 10;
struct edge {//边
int u, v, w;
edge() {}
edge(int uu, int vv, int ww) {
u = uu;
v = vv;
w = ww;
}
};
struct node {//点
int from, i, w; //from=前驱点,i=当前点,w=起点到当前点最短距离
node() {}
node(int pp, int ii, int ww) {
from = pp;
i = ii;
w = ww;
}
bool operator <(const node &a)const {
return a.w &