Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Shortest Path in a Graph visiting all nodes atleast once!

$
0
0

I have been trying to solve following problem from topcoder practice problems:

Problem Link

I have found one of topcoder user's solution, but I could not understand it. Can somebody please explain me the concept used in code.

public class PowerOutage {
public int estmateTimeOut (int[] fromJunction, int[] toJunction, int[] ductLength) {
    int result = -maxDuctLength (fromJunction, toJunction, ductLength, 0);
    for (int i = 0; i < fromJunction.length; i++) {
        result += 2 * ductLength[i];
    }
    return result;
}

public int maxDuctLength (int[] fromJunction, int[] toJunction, int[] ductLength, int ductNumber) {
    int result = 0;
    for (int i = 0; i < fromJunction.length; i++) {
        if (ductNumber == fromJunction[i]) {
         result = Math.max(result, ductLength[i] + maxDuctLength(fromJunction,toJunction,ductLength,toJunction[i]));
        }
    }
    return result;
}

}


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>