Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace csex2
- {
- public class Program
- {
- static bool[,] adjMatrix;
- static int[] path;
- static void ComputeSubGraphs(int n, int m, int cnode, int count)
- {
- if (count == m)
- {
- for (int i = 0; i < m; i++)
- {
- Console.Write("Node[{0}]", path[i]);
- if (i < m - 1)
- Console.Write(" -> ");
- else
- Console.Write("\n");
- }
- path = new int[m];
- }
- else if(cnode+1<n && m-count<n-cnode)
- {
- for (int i = cnode + 1; i < n; i++)
- {
- if (adjMatrix[cnode, i])
- {
- path[count] = i;
- ComputeSubGraphs(n, m, i, count + 1);
- }
- }
- }
- }
- public static void Main(string[] args)
- {
- try
- {
- int n, m;
- Console.Write("Please enter the number of nodes: ");
- var inp = Console.ReadLine();
- n = Int32.Parse(inp);
- Console.Write("Please enter the depth (m) : ");
- inp = Console.ReadLine();
- m = int.Parse(inp);
- adjMatrix = new bool[n, n];
- path = new int[m];
- Console.WriteLine("Enter the adjacent matrix with spaces {0,1}");
- for (var i = 0; i < n; i++)
- {
- inp = Console.ReadLine();
- var inparr = inp.Split(' ');
- if (inparr.Length != n) throw new Exception("Input array length is not correct.");
- for (var j = 0; j < n; j++)
- {
- adjMatrix[i, j] = int.Parse(inparr[j]) == 0 ? false : true;
- }
- }
- ComputeSubGraphs(n, m, -1, 0);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement