Acowdemia II
InterviewTime limit1sMemory limit512 MB
Given K author lists ordered by effort, determine for each pair of N lab members whether one is definitely more senior, using alphabetical tie-breaks.
- Level
Medium5 of 10
- Topics
- Graph, Topological sort
- Solved
- No attempts yet
Problem
Bessie is applying to computer science graduate school and has secured an interview at a prestigious computer science lab. To avoid offending anyone, Bessie wants to determine the relative seniority of the current members of the lab (). No two members have the same seniority, but determining seniority may be tricky. Bessie will look at the lab's publications.
Each publication has an author list, which is an ordering of all lab members. The list is in decreasing order of the effort each member contributed to the paper. If several researchers put in equivalent effort, they are ordered alphabetically. More senior members have more administrative duties, so a more senior researcher never puts in more effort than a more junior researcher.
For example, in a lab with a junior student Elsie, a more senior Prof. Mildred, and a very senior Prof. Dean, there may be a paper (Elsie-Mildred-Dean) if all three put in different amounts of effort (Elsie more than Mildred, and Mildred more than Dean). There may also be a paper in the order (Elsie-Dean-Mildred) if Mildred and Dean put in the same effort and Elsie put in more.
Input
The first line contains two integers and ().
The second line contains space-separated names of the lab members. Each name consists of lowercase letters and is at most 10 characters long.
Each of the next lines contains space-separated names, the author list for one publication.
Output
Print lines with characters each. On line , for any , character is if member is definitely more senior than member , if member is definitely more junior than member , and ? if it is impossible to tell from the given publications. Character on line is B, Bessie's favorite letter.