I’m trying to generate valid trees given certain graph edges (which can be considered as a network). Following is the code which reads the graph edges from a file;
FILE *fin = fopen("somefile.txt", "r");
for (int i = 0; i <=edges; i++) {
fscanf(fin, "%d%d%d", &u, &v, &w);
graph[u][v]=w;
}
fclose(fin);
Now I want to generate the maximum number of possible trees (or topology) for a given root u and a given size N given these edges.
For example, if there are edges; 1—>2 ;1—>3; 3—>4. Now if N is 1; possible trees from u=1 is 1—->2 and 1—>3. If N is 2, then possible trees are 1—>2 & 3 or 1—>3—->4
What would be the best way of achieving this? I’m not concerned about complexity issues. I’ll appreciate the help!
it may not the best implementation but
something like this should work