class Topology {

    static int parity(int[] vs, int[] rank) {
        // count elements which are out of order and by how much
        int count = 0;
        for (int i = 0; i < vs.length; i++) {
            for (int j = i + 1; j < vs.length; j++) {
                if (rank[vs[i]] > rank[vs[j]])
                    count++;
            }
        }
        // odd parity = -1, even parity = 1
        return (count & 0x1) == 1 ? -1 : 1;
    }

}