Pagini recente » Cod sursa (job #627275) | Cod sursa (job #3195190) | Cod sursa (job #901275) | Cod sursa (job #3123597) | Cod sursa (job #3274184)
#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
queue<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(1);
while (!q.empty())
{
int t = q.front();
q.pop();
for (auto w : G[t])
if (dist[w.first] > dist[t] + w.second)
{
dist[w.first] = dist[t] + w.second;
q.push(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;
}