Advertisement
momo2345

Weighted directed undirected

Jan 8th, 2022
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  4. #define ll long long
  5. #define pb push_back
  6. #define F first
  7. #define S second
  8. #define endl "\n"
  9. //undirected
  10. const int mx=1e5+10;
  11. vector<pair<int,int>> adjm[mx];
  12. int main()
  13. {
  14.     suni;
  15.     int n,m;
  16.     cin>>n>>m;
  17.     for(int i=1; i<=m; i++)
  18.     {
  19.         int u,v,w;
  20.         cin>>u>>v>>w;
  21.         adjm[u].pb({v,w});
  22.         adjm[v].pb({u,w});
  23.     }
  24.     for(int i=1; i<=n; i++)
  25.     {
  26.        cout<<"NODE "<<i<<": ";
  27.         for(auto u : adjm[i]) cout<<"to NODE "<<u.F<<" "<<"and COST "<<u.S<<" ";
  28.         cout<<endl;
  29.     }
  30. }
  31.  
  32. //directed
  33. /*int main()
  34. {
  35.     suni;
  36.     int n,m;
  37.     cin>>n>>m;
  38.     for(int i=1; i<=m; i++)
  39.     {
  40.         int u,v,w;
  41.         cin>>u>>v>>w;
  42.         adjm[u].pb({v,w});
  43.     }
  44.     for(int i=1; i<=n; i++)
  45.     {
  46.        cout<<"NODE "<<i<<": ";
  47.         for(auto u : adjm[i]) cout<<"to NODE "<<u.F<<" "<<"and COST "<<u.S<<" ";
  48.         cout<<endl;
  49.     }
  50. }*/
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement