1 Like

Can you please explain your logic? I have forgotten JAVA. Also, I think this is solved using dfs, you don’t seem to have used it, it’s good unless it’s wrong. Please do comment a short explanation for your logic.

Actually logic on which you solved this problem is wrong just check for the case when

**N=6 and S=5 and relations=
0 1,
1 2,
2 3,
3 4,
4 5**

only 0th person was infected but your code is giving output that all 6 were infected .

So correct your logic or in case you require any help behind logic just drop down a comment.

1 Like