We are planning the set-up of the guests for the celebration dinner of the wedding of our beloved friends Gride and Broom. We want to make sure that, at the main table where they will sit, everyone knows everyone else. Also, we want to have as many guests as possible in that main table while obeying that condition. How many guests are we able to accomodate there?
The input tells us who knows whom by listing all acquaintances: first comes a line with a non-negative integer m, the m lines follow, each containing two names and meaning that these two guests know each other. Names are made up of upper- or lower-case letters and are separated by one space. (Gride and Broom do not appear there; there is no need since they know everyone in their wedding.)
The output is the number of guests (not counting the happy pair) that make up the largest possible main table, written in a line, and followed by the names, in string order, of the guests that configure that largest table, one per line.
The time spent by your solution will be compared to that of a (not particularly smart) backtracking. However, too naïve algorithmics incur a serious risk of not being accepted due to slowness.
Input
4 Imar Obrahim Tahmoud Mamza Imar Mamza Imar Tahmoud
Output
3 Imar Mamza Tahmoud
Input
15 Tammar Urie Kassan Satma Kassan Malik Elivia Galak Galak Urie Galak Kassan Kassan Urie Kassan Maniel Jamile Urie Kassan Tammar Maniel Satma Elivia Jamile Galak Malik Malik Urie Elivia Malik
Output
4 Galak Kassan Malik Urie