Week 10 Programming Assignment 1
Due on 2021-04-01, 23:59 IST
Consider a directed graph. It can be represented by an adjacency matrix. The nodes are numbered 1 to n. If there is an edge from node i to node j, there will be a 1 in the (i-1,j-1) position in the adjacency matrix. There are no self loops in the graph. For a node, the number of head ends adjacent to a node is called the indegree of the node and the number of tail ends adjacent to a node is its outdegree. Print 'yes' and the node number if in the given graph there is a node with indegree 2, else print 'no'. Adjacency matrix is given as a line of zeros and ones in row major order i.e, row 1 will be given as input first then the row 2 so on. There will be only one edge with indegree 2.
Example
Input format :
Line 1 - Number of nodes
Line 2 - Adjacency matrix in row major order
Output format : if the condition is satisfied then yes node_number else no
Line 1 - Number of nodes
Line 2 - Adjacency matrix in row major order
Output format : if the condition is satisfied then yes node_number else no
Example
input:
4
0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 0
output
no
No comments:
Post a Comment