#include <bits/stdc++.h>
using namespace std;
// Number of vertices
#define V 6
// 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, 3);
addEdge(adjMatrix, 0, 4);
addEdge(adjMatrix, 1, 4);
addEdge(adjMatrix, 1, 5);
addEdge(adjMatrix, 1, 2);
addEdge(adjMatrix, 2, 5);
addEdge(adjMatrix, 2, 3);
addEdge(adjMatrix, 3, 5);
addEdge(adjMatrix, 4, 5);
cout << "Adjacency Matrix:" << endl;
// Print the adjacency matrix
printAdjMatrix(adjMatrix);
return 0;
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwovLyBOdW1iZXIgb2YgdmVydGljZXMKI2RlZmluZSBWIDYKCi8vIEZ1bmN0aW9uIHRvIGluaXRpYWxpemUgdGhlIGFkamFjZW5jeSBtYXRyaXgKdm9pZCBpbml0QWRqTWF0cml4KGludCBhZGpNYXRyaXhbVl1bVl0pCnsKICAgIC8vIEluaXRpYWxpemUgYWxsIGVsZW1lbnRzIG9mIHRoZSBhZGphY2VuY3kgbWF0cml4IHRvIDAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgVjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQga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