当前位置:网站首页>Heap optimization dijkstra/hash table storage node number
Heap optimization dijkstra/hash table storage node number
2022-06-26 14:24:00 【Honestbutter-】
- The data range of node number has reached 1 e 18 1e18 1e18, Through hash table M A P < L L , i n t > m p MAP<LL,int>mp MAP<LL,int>mp Optimize . use g e t ( ) get() get() Function to convert .
- Note that the shortest circuit length reaches l o n g l o n g long long longlong Level , therefore d [ ] d[] d[] For array initialization f o r for for The loop is initialized to 1 e 13 1e13 1e13
#include<iostream>
#include<queue>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=4e5+100;
typedef long long LL;
typedef pair<LL,int> PLI;
int e[M],ne[M],w[M],h[M],idx;
LL d[M];
map<LL,int>has;
bool st[M];
LL m,xa,xb,s;
LL a,b,l,t;
int n;
void add(LL a,LL b,LL c)
{
e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}
int get(LL x)
{
if(has.count(x)) return has[x];
has[x]=++n;
return has[x];
}
LL dijkstra()
{
priority_queue<PLI,vector<PLI>,greater<PLI>>q;
q.push({
0,xa});
// memset(d,0x3f,sizeof d);
for(int i=1;i<=n;i++) d[i]=1e13;
d[xa]=0;
while(!q.empty())
{
auto t=q.top();
q.pop();
int sed=t.second;
if(!st[sed])
{
st[sed]=true;
for(int i=h[sed];i!=-1;i=ne[i])
{
int j=e[i];
if(d[j]>d[sed]+w[i])
{
d[j]=d[sed]+w[i];
q.push({
d[j],j});
}
}
}
}
if(d[xb]==1e13) return -1;
return d[xb];
}
int main()
{
scanf("%lld%lld%lld%lld",&m,&xa,&xb,&s);
xa=get(xa),xb=get(xb);
memset(h,-1,sizeof h);
while(m--)
{
scanf("%lld%lld%lld%lld",&a,&b,&l,&t);
a=get(a),b=get(b);
add(a,b,l);
if(t==2) add(b,a,l);
}
LL ans=dijkstra();
if(ans==-1) cout<<-1<<endl;
else cout<<(ans+s-1)/s<<endl;
return 0;
}
边栏推荐
- CVPR 2022文档图像分析与识别相关论文26篇汇集简介
- Installation tutorial about origin2019
- C language ---getchar() and putchar()
- From Celsius to the three arrows: encrypting the domino of the ten billion giants, and drying up the epic liquidity
- New specification of risc-v chip architecture
- Caelus - full scene offline mixed Department solution
- How to convert data in cell cell into data in matrix
- [hcsd application development training camp] one line of code second cloud evaluation article - experience from the experiment process
- SwiftUI找回丢失的列表视图(List)动画
- Is expression of D
猜你喜欢
Pycharm远程连接服务器来跑代码
Sword finger offer 18.22.25.52 Double pointer (simple)
Matlab programming related knowledge
PostGIS create spatial database
One article of the quantification framework backtrader read observer
Comparison of disk partition modes (MBR and GPT)
How to convert data in cell cell into data in matrix
ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)
Installation and uninstallation of MySQL software for windows
随机推荐
方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)
Common controls and custom controls
虫子 内存管理 上
Sword finger offer 18.22.25.52 Double pointer (simple)
布局管理器~登录界面的搭建实例
GDAL and opencv smooth and blur TIF images
BP neural network for prediction
ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
VIM auto fill auto indent explanation
Pycharm远程连接服务器来跑代码
Codeforces Round #765 (Div. 2) D. Binary Spiders
Bug memory management
1075 pat judge (25 points)
From Celsius to the three arrows: encrypting the domino of the ten billion giants, and drying up the epic liquidity
Luogu p4513 xiaobaiguang Park
Eigen(3):error: ‘Eigen’ has not been declared
vmware部分设置
服务器创建虚拟环境跑代码
On insect classes and objects
9項規定6個嚴禁!教育部、應急管理部聯合印發《校外培訓機構消防安全管理九項規定》