Question: In an undirected graph, print the adjacent nodes for each node of the graph. Input: Use file redirection to read from the file graph.txt The
In an undirected graph, print the adjacent nodes for each node of the graph.
Input: Use file redirection to read from the file graph.txt
The first line of the input contains only one token, n - the number of nodes of an undirected graph; the nodes then are named 1,...,n.
Next, the boolean adjacency matrix is read in - line by line - n lines in total. The program should check that all diagonal elements are 0 (i.e. false) and that the matrix is symmetric; print an error message if this is not the case.
Output - For each node, print out the name of the adjacent nodes, one line for each node.
Use C++.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
