public static void calculateDistanceToFarthestInput(Gate g){
  if (g.is_unvisited()) {
    g.set_distance_to_input(0);
    g.set_unvisited(false);
    if (g.Type != Gate.GateType.INPUT) {
      for (      Gate child : g.getChildren()) {
        calculateDistanceToFarthestInput(child);
        g.set_distance_to_input(child.get_distance_to_input() + 1);
        if (g.get_farthest_dist2in() < g.get_distance_to_input()) {
          g.set_farthest_dist2in(g.get_distance_to_input());
        }
 else {
          g.set_distance_to_input(g.get_farthest_dist2in());
        }
      }
    }
  }
}

public static void calculateDistanceToFarthestInput ( Gate g ) { if ( g . is_unvisited ( ) ) { g . set_distance_to_input ( 0 ) ; g . set_unvisited ( false ) ; if ( g . Type != Gate . GateType . INPUT ) { for ( Gate child : g . getChildren ( ) ) { calculateDistanceToFarthestInput ( child ) ; g . set_distance_to_input ( child . get_distance_to_input ( ) + 1 ) ; if ( g . get_farthest_dist2in ( ) < g . get_distance_to_input ( ) ) { g . set_farthest_dist2in ( g . get_distance_to_input ( ) ) ; } else { g . set_distance_to_input ( g . get_farthest_dist2in ( ) ) ; } } } } }
compute depth of gate recurse until reaching inputs set gates connected to inputs = = 1 when recursing back up from inputs , dist + = 1 of child if multiple paths , choose farthest
