Subscribe Us

Responsive Advertisement

Advertisement

Graph Representation | Graph Theory | Algorithm and Data Structure

 

Graph Representation | Graph Theory | Algorithm and Data Structure




#include<bits/stdc++.h>

using namespace std;

#define ll long long int

int main()

{

    vector<ll> arr[100];

    ll edge,node;

    cin>>node>>edge;

    while(edge--)

    {

        ll x,y;

        cin>>x>>y;

        arr[x].push_back(y);

        arr[y].push_back(x);

    }

    for(ll i=1;i<=node;i++)

    {

        cout<<i<<"-> ";

        for(ll j=0;j<arr[i].size();j++)cout<<arr[i][j]<<" ";

        cout<<endl;


    }


    return 0;

}



Post a Comment

0 Comments