Pagini recente » Cod sursa (job #2623822) | Cod sursa (job #1542308) | Cod sursa (job #770155) | Cod sursa (job #1879978) | Cod sursa (job #3274189)
#include <iostream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <queue>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <iomanip>
#include <stack>
#include <climits>
#include <unordered_map>
#include <map>
#include <set>
#include <cmath>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
/*
*/
int n, m, dist[50002];
/// nod cost
vector<pair < int, int > > G[50002];
/// cost nod
priority_queue < pair< int, int > > q;
const int oo = 1e9;
bitset<50002> viz;
void BFS()
{
for (int i = 1; i <= n; i++)
dist[i] = oo;
dist[1] = 0;
q.push({ 0, 1 });
while (!q.empty())
{
auto curr = q.top();
q.pop();
for (auto w : G[curr.second])
if (!viz[w.first])
{
viz[w.first] = true;
dist[w.first] = dist[curr.second] + w.second;
q.push({ -dist[w.first], w.first });
}
}
}
int main()
{
int i, j, c;
fin >> n >> m;
while (m--)
{
fin >> i >> j >> c;
G[i].push_back({ j, c });
}
BFS();
for (i = 2; i <= n; i++)
fout << dist[i] << " ";
return 0;
}