# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1167160 | mnnit_prakharg | Valley (BOI19_valley) | Java | 0 ms | 0 KiB |
import java.io.*;
import java.util.*;
public class Main {
public static long fun1(int root, int parent, List<List<Pair>> adj, int[] parentArr, int[] levelArr, long[] shopArr, long[] costTillMeArr, HashSet<Integer> shopsSet, int currDepth, long costTillMe){
parentArr[root] = parent;
levelArr[root] = currDepth;
costTillMeArr[root] = costTillMe;
long minCost = (shopsSet.contains(root)) ? 0 : Long.MAX_VALUE;
for(Pair p: adj.get(root)) {
int x = p.node;
int w = p.weight;
if(x == parent) continue;
long res = fun1(x, root, adj, parentArr, levelArr, shopArr, costTillMeArr, shopsSet, currDepth + 1, costTillMe + w);
if(res == Long.MAX_VALUE) continue;
minCost = Math.min(minCost, res + w);
}
return shopArr[root] = minCost;
}
public static void fun2(int root, int parent, List<List<Pair>> adj, int[] inTimeArr, int[] outTimeArr, int[] timeArr){
inTimeArr[root] = timeArr[0];
timeArr[0]++;
for(Pair p: adj.get(root)) {
int x = p.node;
if(x == parent) continue;
fun2(x, root, adj, inTimeArr, outTimeArr, timeArr);
}
outTimeArr[root] = timeArr[0];
timeArr[0]++;
}