Pagini recente » Clasament drastik_challange_3 | Cod sursa (job #1238183) | Istoria paginii runda/12_lmk_vs | Istoria paginii runda/14_martie_simulare_oji_2024_clasa_10/clasament | Cod sursa (job #2029392)
#include <bits/stdc++.h>
#define pp pair<int,int>
#define x first
#define y second
using namespace std;
const int N_MAX = 50000 + 5;
const int INF = INT_MAX / 2;
int n, m;
vector<pp> vec[N_MAX];
priority_queue <pp, vector<pp >, greater<pp > > q;
int dist[N_MAX];
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
void teldrum (int source){
for(int i = 2; i<=n; ++i)
dist[i] = INF;
q.push({0, source});
while(!q.empty()){
int nod = q.top().y;
int cost = q.top().x;
q.pop();
if(cost > dist[nod])
continue;
for(auto v : vec[nod]){
if(dist[v.x] > cost + v.y){
dist[v.x] = cost + v.y;
q.push({dist[v.x], v.x});
}
}
}
}
int main()
{
fin >> n >> m;
for(int i = 1, a, b, c; i<=m; ++i){
fin >> a >> b >> c;
vec[a].push_back({b,c});
}
teldrum(1);
for(int i = 2; i<=n; ++i)
fout << (dist[i] == INF ? 0 : dist[i]) << " ";
return 0;
}