src/io/github/marwlod/baseball_elimination/BaseballElimination.java
// subset R of teams that eliminates given team; null if not eliminated
subset R of teams that eliminates given team; null if not eliminated
subset R of teams that eliminates given team ; null if not eliminated
public Iterable<String> certificateOfElimination(String team) {
        if (team == null || teamIndexMap.get(team) == null) throw new IllegalArgumentException("Invalid team");
        String eliminatingTeam = getTriviallyEliminatingTeam(team);
        if (eliminatingTeam != null) return Collections.singletonList(eliminatingTeam);
        FlowNetwork flowNetwork = buildFlowNetwork(team);
        FordFulkerson ff = new FordFulkerson(flowNetwork, 0, flowNetwork.V()-1);
        List<String> eliminatingTeams = new ArrayList<>();
        int firstTeamIndex = 1 + (teams.length * (teams.length-1) / 2);
        for (int i = firstTeamIndex; i < flowNetwork.V()-1; i++) {
            if (i - firstTeamIndex == teamIndexMap.get(team)) continue;
            if (ff.inCut(i)) {
                eliminatingTeams.add(teams[i - firstTeamIndex]);
            }
        }
        if (eliminatingTeams.isEmpty()) return null;
        return eliminatingTeams;
    }
public Iterable < String > certificateOfElimination ( String team ) { if ( team == null || teamIndexMap . get ( team ) == null ) throw new IllegalArgumentException ( "Invalid team" ) ; String eliminatingTeam = getTriviallyEliminatingTeam ( team ) ; if ( eliminatingTeam != null ) return Collections . singletonList ( eliminatingTeam ) ; FlowNetwork flowNetwork = buildFlowNetwork ( team ) ; FordFulkerson ff = new FordFulkerson ( flowNetwork , 0 , flowNetwork . V ( ) - 1 ) ; List < String > eliminatingTeams = new ArrayList < > ( ) ; int firstTeamIndex = 1 + ( teams . length * ( teams . length - 1 ) / 2 ) ; for ( int i = firstTeamIndex ; i < flowNetwork . V ( ) - 1 ; i ++ ) { if ( i - firstTeamIndex == teamIndexMap . get ( team ) ) continue ; if ( ff . inCut ( i ) ) { eliminatingTeams . add ( teams [ i - firstTeamIndex ] ) ; } } if ( eliminatingTeams . isEmpty ( ) ) return null ; return eliminatingTeams ; }
subset R of teams that eliminates given team; null if not eliminated
subset R of teams that eliminates given team ; null if not eliminated