Rudro_Debnath

Untitled

Feb 26th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define PSB push_back
  5. #define ll long long
  6. #define MP make_pair
  7. #define FastIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  8. constexpr ll mod = 1e9 + 7;
  9. const ll N=3e6+5;
  10.  
  11. int n,m;
  12. const int INF = 1000000000;
  13. vector<vector<pair<int, int>>> adj;
  14. //vector<int> d(N),p(N);
  15.  
  16. void dijkstra(int s, vector<int> & d, vector<int> & p) {
  17. int n = adj.size();
  18. d.assign(n, INF);
  19. p.assign(n, -1);
  20.  
  21. d[s] = 0;
  22. using pii = pair<int, int>;
  23. priority_queue<pii, vector<pii>, greater<pii>> q;
  24. q.push({0, s});
  25. while (!q.empty()) {
  26. int v = q.top().second;
  27. int d_v = q.top().first;
  28. q.pop();
  29. if (d_v != d[v])
  30. continue;
  31.  
  32. for (auto edge : adj[v]) {
  33. int to = edge.first;
  34. int len = edge.second;
  35.  
  36. if (d[v] + len < d[to]) {
  37. d[to] = d[v] + len;
  38. p[to] = v;
  39. q.push({d[to], to});
  40. }
  41. }
  42. }
  43. }
  44.  
  45. int main(){
  46. FastIO
  47.  
  48. //int n,m;
  49. cin>>n>>m;
  50.  
  51. for(int i=0;i<m;i++){
  52. int a,b,w; cin>>a>>b>>w;
  53. --a,--b;
  54. adj[a].PSB(MP(b,w));
  55. adj[b].PSB(MP(a,w));
  56. }
  57.  
  58.  
  59. //dijkstra(1, d, p);
  60.  
  61.  
  62.  
  63. return 0;
  64. }
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment