突然觉得堆优化$O(log_n)$的复杂度很优啊,然而第n次忘记了$Dijistra$怎么写QAQ发现之前都是用的手写堆,这次用一下$stl$ #include<bits/stdc++.h> #define LL long long using namespace std; int n, m; struct Node { int v, nex, w; Node(, , ) : v(v), nex(nex), w(w) { } } Edge[]; ], stot; void add(int u,
Luogu P4779 利用堆/优先队列快速取得权值最小的点. 在稠密图中的表现比SPFA要优秀. #include<iostream> #include<cstdio> #include<queue> using namespace std; struct data { long long next,to,val; }edge[500005]; long long cnt,head[500005],n,m,s,u,v,w,cost[500005]; bool vis[
许久没有写博客,更新一下~ Dijkstra两种典型写法 1. 朴素Dijkstra 时间复杂度O(N^2) 适用:稠密图(点较少,分布密集) #include <cstdio> #include <iostream> #include <cstring> using namespace std; ; int n, m; int g[N][N], dist[N]; bool st[N]; int dijkstra() { memset(dist, 0
做这道题的动机就是想练习一下堆的应用,顺便补一下好久没看的图论算法. Dijkstra算法概述 //从0出发的单源最短路 dis[][] = {INF} ReadMap(dis); for i = 0 -> n - 1 d[i] = dis[0][i] while u = GetNearest(1 .. n - 1, !been[]) been[u] = 1 for_each edge from u d[edge.v] = min(d[edge.v], d[u] + dis[u][edge.v]
Problem UVA - 11374 - Airport Express Time Limit: 1000 mSec Problem Description In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains in Airp