#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N=1e5+5;
const int M=1e5+5;
vector<pii> e[N];
int dist[N],vis[N];
int n,m;
void dijkstra(int src)
{
memset(dist,0x3f,sizeof(dist));
memset(vis,0,sizeof(vis));
priority_queue<pii, vector<pii>, greater<pii> > pq;
pq.push({0,src});
while(!pq.empty()){
int u=pq.top().second;pq.pop();
if(vis[u]) continue;vis[u]=1;
for(int i=0;i<e[u].size;i++){
int v=e[u][i].first,c=e[u][i].second;
if(!vis[v]&&dist[v]>dist[u]+c){
dist[v]=dist[u]+c;
pq.push({dist[v],v});
}
}
}
}
int main()
{
return 0;
}
dijistra模板(priority_queue优化)
最新推荐文章于 2024-09-11 15:28:58 发布