当前位置:网站首页>[51nod p2673] shortest path [heap optimization Dijk]
[51nod p2673] shortest path [heap optimization Dijk]
2022-06-13 09:35:00 【Ayane.】
analysis :
Does this chip data really need heap optimization f l o y e d floyed floyed Can pass
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define reg register
using namespace std;
typedef long long ll;
const int N=5e4+5;
int n,m,s,t,tot;
int head[N],vis[505];
ll dis[505];
struct Edge{
int to,next,k;
}a[N<<1];
void add(int x,int y,int k)
{
a[++tot]=(Edge){
y,head[x],k};
head[x]=tot;
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
void Dijkstra(int st)
{
memset(dis,0x7f,sizeof dis);
dis[st]=0;
q.push(make_pair(0,st));
while(!q.empty())
{
int x=q.top().second;
q.pop();
if(vis[x]) continue;
vis[x]=1;
for(int i=head[x];i;i=a[i].next)
{
int qwq=a[i].to;
if(dis[qwq]>dis[x]+a[i].k)
{
dis[qwq]=dis[x]+a[i].k;
if(!vis[qwq])
q.push(make_pair(dis[qwq],qwq));
}
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1,x,y,w;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&w);
add(x,y,w);
add(y,x,w);
}
scanf("%d%d",&s,&t);
Dijkstra(s);
printf("%lld",dis[t]);
return 0;
}
边栏推荐
- Class and object -- friend
- IP address introduction
- Tree and binary tree: application of binary tree traversal
- I have summarized the knowledge points of JS [intermediate and advanced] for you
- C language: preprocessing in program environment
- Exercise 8-3 rotate the array to the right (20 points)
- (state compression dp+good) acwing 291 Mondrian's dream
- Tree and binary tree: basic operation and implementation of binary tree
- Resolve importerror:lib*** so--cannot open shared object file: No such... (pycharm/clion reports an error but the shell does not)
- LeetCode 5289. 公平分发饼干(DFS)
猜你喜欢

C language: preprocessing in program environment

Exercise 7-7 string replacement (15 points)

Trees and binary trees: traversal of binary trees

Online debugging tool Arthas advanced

IP address introduction

VGA common resolution and calculation method

Online debugging tool Arthas Foundation

Jenkins接入Openldap用户认证

VGA常用分辨率及计算方法

202012 CCF test questions
随机推荐
Haproxy + keepalived for high availability load balancing of MySQL
C language: preprocessing in program environment
Trees and binary trees: traversal of binary trees
turtle库的使用数字时钟模拟时钟动态显示
Acwing 787. Merge sort
时间戳转localDate
Summary of string, vector and array learning
Yolov5 face learning notes
Summary of random number learning
[implementation of depth first search]
Classes and objects -- encapsulation
LeetCode 583. 两个字符串的删除操作
Tree and binary tree: storage structure of binary tree
(dfs) acwing 842. Arrange numbers
Calculate the number of days between two times (supports cross month and cross year)
ROS2之OpenCV人脸识别foxy~galactic~humble
Attack and defense world PWN shell
VDD,DVDD,AVDD,VCC,AFVDD,DOVDD,IOVDD
(state compression dp+ binary) acwing 91 Shortest Hamilton path
Jenkins accédant à l'authentification de l'utilisateur openldap

