An improvement on Braegh's answer.
-
Ask everyone what Y1's identity is. Majority is correct. If Y1 is a villager or a knave, proceed torepeat this step two. Otherwise, proceed to step three.
-
Choose one of the people in the majority; they are a knight. Proceed to step threetwo.
-
Use the knight to determine everyone else's identity.