private static boolean areConnected(Node a, Node b) {
        Set<Node> visited = new HashSet<>();
        Set<Node> toVisit = new HashSet<>();
        toVisit.add(a);
        while (!toVisit.isEmpty()) {
            Set<Node> nextToVisit = new HashSet<>();
            for (Node next : toVisit) {
                if (next == b) {
                    return true;
                }
                else {
                    for (Node neighbour : next.neighbours) {
                        if (!visited.contains(neighbour)) {
                            nextToVisit.add(neighbour);
                        }
                    }
                    visited.add(next);
                }
            }
            toVisit = nextToVisit;
        }
        return false;
    }