import java.util.ArrayList; /* Basic tree stuff. I wouldn't recommend tweaking this unless you have some * ideas for optimizations. Or if my code is bad; it's been a long while since I * wrote Java. However, please modify `next` below to change functionality as * described in the Overleaf */ class Tree { private long value; private ArrayList children; public Tree(long tree_value, ArrayList tree_children) { value = tree_value; children = new ArrayList(); for (long child : tree_children) { children.add(new Tree(child, new ArrayList())); } } public void step() { if (children.isEmpty()) { ArrayList xs = next(value); for (long val : xs) { children.add(new Tree(val, new ArrayList())); } return; } for (Tree child : children) { child.step(); } } public ArrayList longestPath() { ArrayList retval = new ArrayList(); if (children.isEmpty()) { retval.add(value); return retval; } int max_length = 0; for (Tree child : children) { ArrayList temp = child.longestPath(); if (temp.size() > max_length) { max_length = temp.size(); retval = temp; } } retval.add(0, value); return retval; } /* TODO please tweak this function according to what you want the code to do */ public ArrayList next(long val) { ArrayList new_xs = new ArrayList(); return new_xs; } }