Cod sursa(job #3323705)

Utilizator oliv_1Bostinescu Octavian oliv_1 Data 19 noiembrie 2025 10:08:02
Problema Algoritmul lui Dijkstra Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.15 kb
/******************************************************************************

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;
}