luogu#P2256. 一中校运会之百米跑
一中校运会之百米跑
Background
Amid a crowd of couples showing PDA, Su the "xue shen" strides with firm (?) steps toward the m starting line. He notices that there are too many participants, and even the PE teacher is overwhelmed. The PE teacher spots Su, who is the class sports rep, and asks him for help.
However, Su needs to warm up, or he might cramp halfway through the run. So he turns to you. If you help the teacher solve the problem, the teacher will give you points.
Problem Description
Suppose there are () competitors.
The teacher will tell you the names of these competitors.
Then the teacher will say () sentences, each stating that student A and student B are in the same group.
If student A and student B are in the same group, and student B and student C are also in the same group, then student A and student C are in the same group.
After that, the teacher will ask you () questions, each asking whether student X and student Y are in the same group.
If they are, output Yes.; otherwise, output No..
Input Format
The first line contains and .
The next lines each contain the name of one student.
The next lines each contain two names, both guaranteed to have appeared in the above lines, indicating that these two competitors are in the same group.
Then an integer is given.
Then follow queries. Each query consists of two names, asking whether the two students are in the same group.
Output Format
For each of the teacher’s queries, output Yes. or No..
10 6
Jack
Mike
ASDA
Michel
brabrabra
HeHe
HeHE
papapa
HeY
Obama
Jack Obama
HeHe HeHE
brabrabra HeHe
Obama ASDA
papapa Obama
Obama HeHE
3
Mike Obama
HeHE Jack
papapa brabrabra
No.
Yes.
Yes.
Hint
Translated by ChatGPT 5