1 / 2
Feb 2018

public void solve(int testNumber, InputReader in, OutputWriter out) {
int b = in.nextInt();
int comm = in.nextInt();
HashSet males = new HashSet<>();
HashSet females = new HashSet<>();
boolean failed = false;
for (int i = 0; i < comm; i++) {
int first = in.nextInt();
int second = in.nextInt();
if ((males.contains(first) && males.contains(second)) || (females.contains(first) && females.contains(second))) {
failed = true;
break;
}
if (males.contains(first)) {
females.add(second);
} else if (males.contains(second)) {
females.add(first);
} else if (females.contains(first)) {
males.add(second);
} else if (females.contains(second)) {
males.add(first);
} else {
males.add(first);
females.add(second);
}
}

    out.printLine("Scenario #" + testNumber + ":");
    if (failed) {
        out.printLine("Suspicious bugs found!");
    } else {
        out.printLine("No suspicious bugs found!");
    }
}
  • created

    Feb '18
  • last reply

    Feb '18
  • 1

    reply

  • 913

    views

  • 2

    users

  • 1

    like

I don’t know enough java to be able to test your program, but I suspect this bit.

} else {
males.add(first);
females.add(second);
}

You don’t yet know anything about the first or second bugs, so you arbitrarily assign one as male and the other as female, but you might find information further into the data that lets you know for sure.

What does your code say for this case?

1
8 4
1 2
3 4
6 5
8 7
3 6
4 5