#P7369. [COCI 2018/2019 #4] Elder
[COCI 2018/2019 #4] Elder
Description
After watching eight Harry Potter movies in a week, Nikola realized how powerful the Elder Wand is. If the Elder Wand currently serves wizard A, and wizard A is defeated by wizard B, then the Elder Wand will start serving wizard B.
Now several wizards will have duels. Given the wizard the Elder Wand initially serves and the results of the duels, find:
- After the duels, who the Elder Wand serves.
- How many wizards has the Elder Wand served in total?
Input Format
The first line contains one uppercase letter, representing the wizard the Elder Wand initially serves.
The second line contains an integer , representing the number of duels.
Each of the next lines contains two uppercase letters and separated by a space, meaning that in the -th duel, wizard defeated wizard .
Output Format
Output one uppercase letter on the first line, representing the answer to question 1.
Output one integer on the second line, representing the answer to question 2.
A
3
B A
C B
D A
C
3
N
5
D A
N B
B A
C D
F A
N
1
X
4
A X
B X
X A
D A
X
2
Hint
Explanation for Sample 1
The Elder Wand initially serves wizard A. After the first duel, the Elder Wand starts serving B. After the second duel, the Elder Wand starts serving C. The third duel after that does not affect who the Elder Wand serves.
Constraints
For of the testdata, .
Scoring
In each test case, the first line is worth points and the second line is worth points, for a total of points per test case. If you only want to get the points for one line, please output any number on the other line as well; otherwise, it cannot be judged correctly.
A Special Judge is needed for scoring; see the attachment for details.
Notes
The score of this problem follows the original COCI setting, with a full score of .
Translated from COCI2018-2019 CONTEST #4 T1 Elder.
Translated by ChatGPT 5
京公网安备 11011102002149号