模板
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define R register
#define TIME static_cast<double>(clock()-start)/CLOCKS_PER_SEC
signed main()
{
clock_t start=clock();
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
return 0;
}struct node {
int x, y;
bool operator < (const node &a) const {
return x > a.x;
}
};#include<bits/stdc++.h>
using namespace std;
struct Edge{
int v;
int w;
bool operator<(Edge b)const{
return w>b.w;
}
}now,tmp,et,t1,t2;
int n,m,dis[500001],vis[500001];
int const inf=0x3f3f3f;
vector<Edge> es[500001];
void dijkstra(int s);
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
es[i].clear();
while(m--)
{
int u,v,w;
cin>>u>>v>>w;
t1.v=v;
t1.w=w;
t2.v=u;
t2.w=w;
es[u].push_back(t1);
es[v].push_back(t2);
}
dijkstra(1);
for(int i=2;i<=n;i++)
cout<<dis[i]<<endl;
return 0;
}
void dijkstra(int s)
{
memset(dis,inf,sizeof(dis));
memset(vis,0,sizeof(vis));
dis[s]=0;
now.v=s;
now.w=0;
priority_queue<Edge> q;
q.push(now);
while(!q.empty())
{
now=q.top();
q.pop();
if(vis[now.v]==1)
continue;
vis[now.v]=1;
int len=es[now.v].size();
for(int i=0;i<len;i++)
{
tmp=es[now.v][i];
if(dis[now.v]+tmp.w<dis[tmp.v])
{
dis[tmp.v]=dis[now.v]+tmp.w;
et.v=tmp.v;
et.w=dis[tmp.v];
q.push(et);
}
}
}
}