All Walks of length n from the first node

A computer network can be represented as a graph. Let G = (V, E) be an undirected graph, V = (v1,v2,v3,...,vm) represents all nodes, where m is the number of nodes, and E represents all edges. The first node is v1 and the last node is vm . The number of edges is k. Define the adjacency matrix A = (aij)m×m where aij = 1 if {vi,vj} ∈ E, otherwise aij = 0 An example of the adjacency matrix and its corresponding graph are as follows: Calculate  01010  1 0 1 0 0   0 1 0 1 1  10101 00110 An =A·A···A | {z } n and use the Boolean operations where 0+0 = 0,0+1 = 1+0 = 1,1+1=1,and0•0=0•1=1•0=0,1•1=1. Theentryin row i and column j of An is 1 if and only if at least there exists a walk of length n between the i-th and j-th nodes of V. In other words, the distinct walks of length n between the i-th and j-th nodes of V may be more than one. Note that the node in the paths can be repetitive. The following example shows the walks of length 2.  01010 01010 10101 101001010001011  A2=A·A=0 1 0 1 1·0 1 0 1 1=1 0 1 1 1 101011010101111 00110 00110 11111 Write programs to do above calculation and print out all distinct walks of length n. (In this problem we let the maximum walks of length n be 5 and the maximum number of nodes be 10.) Input The input file contains a number of test examples, the test examples are separated by ‘-9999’. Each test example consists of the number of nodes and the length of walks in the first row, and then the adjacency matrix. Output The output file must contain all distinct walks of the length n, and with all its nodes different, from the first node, listed in lexicographical order. In case there are not walks of length n, just print ‘no walk of length n’ Separate the output of the different cases by a blank line.

2/2 Sample Input 52 01010 10100 01011 10101 00110 -9999 53 01010 10100 01011 10101 00110 Sample Output (1,2,3) (1,4,3) (1,4,5) (1,2,3,4) (1,2,3,5) (1,4,3,2) (1,4,3,5) (1,4,5,3)