Here is my solution to the problem, it is passing for few task and failing for many.
link
My Algorithm:
This is basically a complete m-tree with n levels and m child to each parent. So answer to the problem is no of leaf nodes(m^n).
when considering the special edges.
Make two list one to sort based on starting of the edge(specialEdgesSI) and one to sort based on ending of the edge (specialEdgesEI) and iterate with the specialEdgesEI list and use specialEdgesSI for cases in which
a special edge starts at the end of another special edge.
sPaths(e) = no of paths till l1-1;
a,b,…,n - special edge ending at (l1,v1);
no of paths added by a special edge(e1) = (sPaths(e1)*(m^(n-l2)))+ sPaths(a)+sPaths(b)+…+sPaths(n);
I have tested it with few tc, one of the few is the following:
8 4 32
0 0 1 0
0 0 1 0
0 0 4 1
0 0 4 1
0 0 9 0
0 0 7 3
0 0 2 3
0 0 8 3
1 0 5 0
1 0 5 0
1 0 3 1
1 1 3 1
1 2 7 2
1 3 2 3
2 0 3 1
3 0 5 0
3 2 4 2
3 3 7 0
3 3 5 3
5 0 6 0
5 0 7 1
5 1 6 1
5 2 9 0
5 3 6 3
5 3 8 3
7 1 8 0
7 1 9 0
7 1 8 2
8 0 9 0
8 1 9 0
8 2 9 0
8 2 9 0
Is there anything wrong or miss in my algorithm or/and my code?