#include <iostream>
using namespace std;

int main()
{
    int N, M, i, j;
    int max = 0;
    do {
        cout << "Enter the number of vertices and the number of edges: \n";
        cin >> N >> M;
    } while (N <= 1 || N >= 50 && M <= 1 || M >= 500);
    cout << "Enter the matrix : \n";

    int** mass = new int* [N];
    for (int i = 0; i < N; i++)
        mass[i] = new int[M];

    for (i = 0; i < N; i++)
    {
        for (j = 0; j < M; j++)
        {
            cin >> mass[i][j];
        }
    }

    cout << "\n";
    
 
    int ones[2], cnt, A[50][50];

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            A[i][j] = 0;
        }
    }

    for (i = 0; i < M; i++)
    {
        cnt = 0;
        for (j = 0; j < N; j++)
        {
            if (mass[j][i] == 1)
            {
                ones[cnt++] = j;
            }
        }
        A[ones[0]][ones[1]] = 1;
        A[ones[1]][ones[0]] = 1;
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
            cout << A[i][j] << " ";
        cout << endl;
    }

    cout << "\n";
    system("pause");
    return 0;
}