Pagini recente » Cod sursa (job #2599912) | Cod sursa (job #2621178) | Clasament bon | Cod sursa (job #2983962) | Cod sursa (job #2259816)
#include<bits/stdc++.h>
using namespace std ;
#define cin in
#define cout out
priority_queue<pair<int,int> , vector<pair<int,int>> , greater <pair<int,int>>> q ;
vector<pair<int,int>> g[50010];
int rez[50010];
void dijkstra(){
q.push(make_pair(0,1));
while(q.size()){
pair<int,int> x = q.top();
q.pop();
if(rez[x.second] != 1 << 30)
continue;
rez[x.second] = x.first;
for(auto it : g[x.second]){
q.push(make_pair(x.first+it.second, it.first));
}
}
}
int main(){
ifstream in("dijkstra.in");
ofstream out("dijkstra.out");
int n , m ;
cin >> n >> m ;
for(int i = 0 ; i < m ; i ++ )
{
int x, y , c ;
cin >> x >> y >> c ;
g[x].push_back(make_pair(y,c));
}
for(int i = 1 ; i <= n ; i ++)
rez[i] = 1 << 30 ;
dijkstra();
for(int i = 2 ; i <= n ; i ++)
if(rez[i] != 1 << 30)
cout << rez[i] << " ";
else
cout << "0 " ;
}