标签:scanf turn using ret div struct std class tmp
#include<iostream> #include<cstdio> #include<queue> using namespace std; int dis[200001],head[200001]; int n,m,a,b,c,s,cnt; bool vis[200001]; struct edge { int to; int dis; int next; }; edge e[500001]; struct node { int dis; int pos; bool operator<(const node &x)const { return x.dis<dis; } }; void add_edge(int u,int v,int d) { cnt++; e[cnt].to=v; e[cnt].dis=d; e[cnt].next=head[u]; head[u]=cnt; } std::priority_queue <node> q; void dijkstra() { dis[s]=0; q.push((node){0,s}); while(!q.empty()) { node tmp=q.top(); q.pop(); int x=tmp.pos,d=tmp.dis; if(vis[x]) continue; vis[x]=1; for(int i=head[x];i;i=e[i].next) { int y=e[i].to; if(dis[y]>dis[x]+e[i].dis) { dis[y]=dis[x]+e[i].dis; if(!vis[y]) q.push((node){dis[y],y}); } } } } int main() { scanf("%d%d%d",&n,&m,&s); fill(dis+1,dis+n+1,0x7fffffff); for(int i=1;i<=m;i++) { scanf("%d%d%d",&a,&b,&c); add_edge(a,b,c); //add_edge(b,a,c); } dijkstra(); for(int i=1;i<=n;i++) printf("%d ",dis[i]); return 0; }
标签:scanf turn using ret div struct std class tmp
原文地址:https://www.cnblogs.com/liumengliang/p/13184300.html