#include <bits/stdc++.h>
using namespace std;
// Number of vertices
#define V 5
// Function to initialize the adjacency matrix
void initAdjMatrix(int adjMatrix[V][V])
{
// Initialize all elements of the adjacency matrix to 0
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
adjMatrix[i][j] = 0;
}
}
}
// Function to add an edge to the graph
void addEdge(int adjMatrix[V][V], int u, int v)
{
// Mark the edge between vertices u and v as 1
adjMatrix[u][v] = 1;
// For undirected graph, mark opposite edge as well
//adjMatrix[v][u] = 1;
}
// Function to print the adjacency matrix
void printAdjMatrix(int adjMatrix[V][V])
{
// Print the adjacency matrix
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
cout << adjMatrix[i][j] << " ";
}
cout << endl;
}
}
int main()
{
int adjMatrix[V][V];
// Initialize the adjacency matrix
initAdjMatrix(adjMatrix);
// Add edges to the graph
addEdge(adjMatrix, 0,1);
addEdge(adjMatrix, 1, 2);
addEdge(adjMatrix, 2, 2);
addEdge(adjMatrix, 0, 3);
addEdge(adjMatrix, 3, 0);
addEdge(adjMatrix, 4,3);
cout << "Adjacency Matrix:" << endl;
// Print the adjacency matrix
printAdjMatrix(adjMatrix);
return 0;
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwovLyBOdW1iZXIgb2YgdmVydGljZXMKI2RlZmluZSBWIDUKCi8vIEZ1bmN0aW9uIHRvIGluaXRpYWxpemUgdGhlIGFkamFjZW5jeSBtYXRyaXgKdm9pZCBpbml0QWRqTWF0cml4KGludCBhZGpNYXRyaXhbVl1bVl0pCnsKICAgIC8vIEluaXRpYWxpemUgYWxsIGVsZW1lbnRzIG9mIHRoZSBhZGphY2VuY3kgbWF0cml4IHRvIDAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgVjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBWOyBqKyspIHsKICAgICAgICAgICAgYWRqTWF0cml4W2ldW2pdID0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