Tildelt

UNITED NATION SEATING

The United Nations hosts many events in which they have to seat representatives of various countries. Sometimes, countries are not on good terms and it would be bad form to seat the representatives of these countries next to each other. For example currently Pakistan is not too happy with the United States and would prefer not to sit next them at the dinner table. You work for the United Meeting of Diplomats Service (UMDs) and need to write a program to help them seat the diplomats. You can assume the table at which they will be seated is round so that the first country will sit next to the last country. Each country will present you with a list of “undesirable” neighbors which they want to avoid and your program will output a list of countries which represents a seating chart for the event.

For example Pakistan wants to avoid India, and the United States. The United States wants to avoid China. India wants to avoid France. China wants to avoid the US. France wants to avoid India. One possible seating is : Pakistan, China, India, US, and France.

Input All input will be from the keyboard. The first line of input n will be an integer containing the number of test cases. The first line of a test case will contain an integer m indicating the number of countries to be represented. The next m ( m > 1 )lines will contain each countries list of undesirable neighbors. The list of neighbors to avoid begins with an integer k ( k > 0) followed by k + 1 country codes (each separated by a single space) . Each country code will be 3 letters. The first country code is the name of country submitting the list. The remaining k country codes represent the list of countries to be avoided.

Output For each case there will be 1 line of output containing a list of countries or the word impossible . The list of the countries start with the first country in the input list and then continue in order. If more than one list satisfies all the criteria print the one which comes first alphabetically.

Sample Input

2

5

2 PAK IND USA

1 USA CHI

1 IND FRA

1 CHI USA

1 FRA IND

5

2 PAK IND USA

1 USA CHI

2 IND CHI FRA

2 CHI USA IND

1 FRA IND

Sample Output PAK CHI IND USA FRA

impossible

Færdigheder: C++ Programmering

Se mere: round events, united, fra, united nations seating chart, list states usa, chart output, dinner service, united states countries, usa fra, seat chart, need print country, usa states codes, countries states code, chart print, india event, list usa countries, need list states countries, usa states list, events seating, list usa states, countries usa list, seated, print chart, space india, country codes

Om arbejdsgiveren:
( 0 bedømmelser ) United States

Projekt-ID: #5988816

1 freelancer byder i gennemsnit $10 for dette job

vano101

Hired by the Employer

$10 USD på 1 dag
(343 bedømmelser)
6.4