Hello. Can Someone help me in order to add new posibilities to a program that work fine but I need add new possibility.
The original version was copied from GeekForGeeks, to find how many Cycles with n Nodes have an nondirected graph, that solution working fine but I need add to the solution what are the count of nodes in the solution, and when whatever nodes are repetead count as one.
I was try to but can't find the solution. Below are a copy of initial solution.
Thanks so much for your time.
Best regards.
LEG.
What I have tried:
using System;
class GFG
{
public static int V = 5;
static int count = 0;
static void DFS(int [,]graph, bool []marked,
int n, int vert, int start)
{
marked[vert] = true;
if (n == 0)
{
marked[vert] = false;
if (graph[vert, start] == 1)
{
count++;
return;
}
else
return;
}
for (int i = 0; i < V; i++)
if (!marked[i] && graph[vert, i] == 1)
DFS(graph, marked, n - 1, i, start);
marked[vert] = false;
}
static int countCycles(int [,]graph, int n)
{
bool []marked = new bool[V];
for (int i = 0; i < V - (n - 1); i++)
{
DFS(graph, marked, n - 1, i, i);
marked[i] = true;
}
return count / 2;
}
public static void Main()
{
int [,]graph = {{0, 1, 0, 1, 0},
{1, 0, 1, 0, 1},
{0, 1, 0, 1, 0},
{1, 0, 1, 0, 1},
{0, 1, 0, 1, 0}};
int n = 4;
Console.WriteLine("Total cycles of length "+
n + " are "+
countCycles(graph, n));
}
}