মডিউল ১৩_৫ঃ এজ লিস্ট টু ম্যাট্রিক্স




Previousমডিউল ১৩_৪ঃ এডজেসেন্সি লিস্ট টু এডজেসেন্সি ম্যাট্রিক্স পার্ট-২Nextমডিউল ১৩_৬ঃ এডজেসেন্সি ম্যাট্রিক্স টু এডজেসেন্সি লিস্ট
Last updated




Last updated
// Some code
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
mat[i][j] = -1;
if (i == j)
mat[i][j] = 0;
}
}// Some code
while (e--)
{
int a, b, c;
cin >> a >> b >> c;
mat[a][b] = c;
mat[b][a] = c;
} // Some code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, e;
cin >> n >> e;
int mat[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
mat[i][j] = -1;
if (i == j)
mat[i][j] = 0;
}
}
while (e--)
{
int a, b, c;
cin >> a >> b >> c;
mat[a][b] = c;
mat[b][a] = c;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << mat[i][j] << " ";
}
cout << endl;
}
return 0;
}