Pagini recente » Cod sursa (job #2013889) | Cod sursa (job #618233) | Cod sursa (job #1784752) | Cod sursa (job #47904) | Cod sursa (job #3323705)
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
vector<pair<int,int>>v[50005];
priority_queue<pair<int,int>>pq;
int dist[50005];
int main()
{
ifstream cin("dijkstra.in");
ofstream cout("dijkstra.out");
// cout<<777777;
int n,m,a,b,c;
cin>>n>>m;
for(int i=0; i<m; i++)
{
cin>>a>>b>>c;
v[a].push_back({b,c});
}
pq.push({0,1});
for(int i=2; i<=n; i++)
dist[i]=10000000;
while(pq.size()>0)
{
pair<int,int>g= pq.top();
pq.pop();
int nodcur=g.second, val=-g.first;
for(auto var : v[nodcur])
{
if(dist[var.first]>var.second+val)
{
dist[var.first]=var.second+val;
pq.push({-dist[var.first], var.first});
}
}
}
for(int i=2; i<=n; i++)
cout<<dist[i]%10000000<<" ";
return 0;
}