public static void constructRelations(Scanner in) {
        int n = in.nextInt();

        relations = new HashMap<Integer, Set<Integer>>();
        persons = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            persons.add(x);
            persons.add(y);
            if (!relations.containsKey(x)) {
                relations.put(x, new HashSet<Integer>());
            }
            relations.get(x).add(y);
            if (!relations.containsKey(y)) {
                relations.put(y, new HashSet<Integer>());
            }
            relations.get(y).add(x);
        }

    }