eolymp
bolt
Try our new interface for solving problems
Məsələlər

Super Phyllis

Super Phyllis

Phyllis works for a large, multi-national corporation. She moves from department to department where her job is to uncover and remove any redundancies inherent in the day-to-day activities of the workers. And she is quite good at her job. During her most recent assignment, she was given the following chart displaying the chain of command within the department: \includegraphics{https://static.e-olymp.com/content/94/94d900f182a3e6c55d19fcdf31d0de0ece7cfd93.jpg} \textit{\textbf{Figure 1}} Whenever anyone needs to send a report to their bosses, they use the above chart, sending one report along each arrow. Phyllis realized almost instantly that there were redundancies here. Specifically, since \textbf{D} sends a report to \textbf{B} and \textbf{B }sends a report to \textbf{A}, there's really no need for \textbf{D} to send a report to \textbf{A} directly, since it will be summarized in the report \textbf{B} sends to \textbf{A}. Thus the connection from \textbf{D} to \textbf{A} can be removed. If there had also been a connection from \textbf{C} to \textbf{B}, then the connections from \textbf{D} to \textbf{B} and \textbf{C} to \textbf{A} could have been removed as well. Phyllis would like your help with this. Given a description of a chart like the one above, she would like a program that identifies all connections that can be removed from the chart. \InputFile The first line of each test case will contain a positive integer \textbf{m} indicating the number of connections in the chart. Following that will be \textbf{m} lines each containing two strings \textbf{s_1 s_2} indicating that there is a connection from employee \textbf{s_1} to his/her boss \textbf{s_2}. In any test case there will be no more than \textbf{200} employees listed and no connection will appear more than once. A line containing a single \textbf{0} will terminate the input. \OutputFile For each test case, output the number of connections that should be removed followed by a list of the deleted connections in lexicographic order. Connection \textbf{s_1 s_2} should be represented by the string \textbf{s_1},\textbf{s_2}.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
5
D B
D C
D A
B A
C A
6
D B
D C
D A
C B
B A
C A
1
Danny Tessa
0
Çıxış verilənləri #1
Case 1: 1 D,A
Case 2: 3 C,A D,A D,B
Case 3: 0
Mənbə ACM ICPC East Central North America Region 2013