Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define suni ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
- #define ll long long
- #define pb push_back
- #define F first
- #define S second
- #define endl "\n"
- //undirected
- const int mx=1e5+10;
- vector<pair<int,int>> adjm[mx];
- int main()
- {
- suni;
- int n,m;
- cin>>n>>m;
- for(int i=1; i<=m; i++)
- {
- int u,v,w;
- cin>>u>>v>>w;
- adjm[u].pb({v,w});
- adjm[v].pb({u,w});
- }
- for(int i=1; i<=n; i++)
- {
- cout<<"NODE "<<i<<": ";
- for(auto u : adjm[i]) cout<<"to NODE "<<u.F<<" "<<"and COST "<<u.S<<" ";
- cout<<endl;
- }
- }
- //directed
- /*int main()
- {
- suni;
- int n,m;
- cin>>n>>m;
- for(int i=1; i<=m; i++)
- {
- int u,v,w;
- cin>>u>>v>>w;
- adjm[u].pb({v,w});
- }
- for(int i=1; i<=n; i++)
- {
- cout<<"NODE "<<i<<": ";
- for(auto u : adjm[i]) cout<<"to NODE "<<u.F<<" "<<"and COST "<<u.S<<" ";
- cout<<endl;
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement