plduhoux
2/21/2018 - 1:03 AM

isTournament

boolean isTournament(int n, int[] fromV, int[] toV) {
    Map<String, Integer> s = new HashMap<>();
    for (int j = 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
            s.put(j + "->" + k, 0);
        }
    }
    for (int j = 0; j < fromV.length; j++) {
        if (fromV[j] == toV[j]) return false;
        String tmp = Math.min(fromV[j], toV[j]) + "->" + Math.max(fromV[j], toV[j]);
        if (s.get(tmp) != 0) return false;
        s.put(tmp, 1);
    }
    for (Integer k : s.values()) {
        if (k == 0) return false;
    }
    return true;
}