当前位置:网站首页>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;
}
边栏推荐
- STM32F1和GD32F1有什么区别?
- Hard (magnetic) disk (II)
- d的is表达式
- PostGIS create spatial database
- A must for programmers, an artifact utools that can improve your work efficiency n times
- Knowledge about adsorption
- Lucky numbers in the matrix
- Setup instance of layout manager login interface
- Bug STL string
- Niuke challenge 53:c. strange magic array
猜你喜欢

Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient

Correlation analysis related knowledge

7.consul service registration and discovery

Sword finger offer 06.24.35 Linked list

Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills

STM32F1和GD32F1有什么区别?

BP neural network for prediction

Server create virtual environment run code

布局管理器~登录界面的搭建实例

ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
随机推荐
Online bull Blogger
ArcGIS cannot be opened and displays' because afcore cannot be found ' DLL, solution to 'unable to execute code'
Svn commit error after deleting files locally
Bug STL string
C language ---getchar() and putchar()
同花顺股票开户选哪个证券公司是比较好,比较安全的
vmware部分设置
In insect classes and objects
Bucket of P (segment tree + linear basis)
SwiftUI找回丢失的列表视图(List)动画
Sword finger offer 10 Ⅰ 10Ⅱ. 63 dynamic planning (simple)
ThreadLocal giant pit! Memory leaks are just Pediatrics
Insect operator overloaded a fun
Practice with the topic of bit operation force deduction
Setup instance of layout manager login interface
虫子 内存管理 下 内存注意点
7.consul service registration and discovery
Never use redis expired monitoring to implement scheduled tasks!
windows版MySQL软件的安装与卸载
New specification of risc-v chip architecture