Advertisement
Rentib

Untitled

Feb 14th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. priority_queue<pair<long long, long long>> q;
  4. vector<long long> odl(100007, LLONG_MAX);
  5. vector<pair<long long, long long>> G[100007];
  6. int main(){
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10. long long n, m, v;
  11. long long dist;
  12. cin >> n >> m;
  13. for(long long i = 0, a, b, c;i < m;i++){
  14. cin >> a >> b >> c;
  15. G[b].emplace_back(a, c);
  16. }
  17. q.emplace(0ll, 1);
  18. while(!q.empty()){
  19. tie(dist, v) = q.top();
  20. q.pop();
  21. if(-dist > odl[v])
  22. continue;
  23. odl[v] = -dist;
  24. for(auto i : G[v])
  25. if(odl[i.first] > -dist + i.second)
  26. q.emplace(dist - i.second, i.first);
  27. }
  28. for(long long i = 1;i <= n;i++){
  29. if(odl[i] == LLONG_MAX)
  30. cout << "+oo\n";
  31. else
  32. cout << odl[i] << '\n';
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement