Graph Adjacent Node Found

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, e, i, j, x, y;

    cout << "Enter Node Number :: ";
    cin >> n;

    cout << "Enter Edge Number :: ";
    cin >> e;

    int a[n][n];

    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            a[i][j] = 0;
        }
    }

    cout << endl <<"Input Edge :: " << endl;
    for(i=1;i<=e;i++)
    {
        cin >> x >> y;
        a[x][y] = 1;
        a[y][x] = 1;
    }

    cout << endl <<"Matrix Are :: " << endl;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }

    cout << endl << "Adjacent Node Are :: " << endl;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i][j] == 1)
                cout << j << " ";
        }
        cout << endl;
    }

    return 0;
}

Comments