forked from codemistic/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode1.cpp
More file actions
34 lines (30 loc) · 742 Bytes
/
code1.cpp
File metadata and controls
34 lines (30 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Code for Adjacency Matrix
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int inf = 1e9 + 7;
int main()
{
int v;
v = 5;
int mat[v][v];
memset(mat, 0, sizeof(mat));
// adding edges
// 0-1 0-4 1-3 3-4 2-3
mat[0][1] = mat[1][0] = 1;
mat[0][4] = mat[4][0] = 1;
mat[1][3] = mat[3][1] = 1;
mat[3][4] = mat[4][3] = 1;
mat[2][3] = mat[3][2] = 1;
// if graph is undirected then mat is symmetric otherwise it depends on edges
cout << "CHECK MATRIX: " << endl;
for (int i = 0; i < v; i++)
{
for (int j = 0; j < v; j++)
{
cout << mat[i][j] << " ";
}
cout << endl;
}
return 0;
}