Gosu
Time limit1sMemory limit1024 MB
Given a tournament where each pair has a winner, find a vertex whose maximum shortest directed distance to every other vertex is as small as possible.
- Level
Hard8 of 10
- Topics
- Graph, BFS, Shortest path, Greedy
- Solved
- No attempts yet
Problem
Ho is an expert in a martial art called Taebo. She runs a Taebo school, and there are students in her school. Ho is too old to teach Taebo, so she is going to hand over her school to one of her students. To find a suitable candidate, Ho made all pairs of students do a Taebo matchup with each other. In a Taebo matchup, exactly one person wins the match and the other person loses the match. Ho thinks a student is good enough to receive her school if the student is a Gosu of Taebo.
Gosu is a Korean word which means a person who is very good at games, sports, competitive programming, etc. In Taebo, Gosu has a different meaning.
Let a winning path from player to player be a sequence of integers , where student has won against student for all . We call the length of this winning path. For example, if there exists a winning path of length 1, we can immediately know that has won against student . If there exists a winning path of length 2, then may not have won against directly, but there exists some other player that has won against, and has won against .
The distance is defined as a minimum length of a winning path from to , if such exists. There could be a case that cannot find a winning path to . In that case, we define . Note that the path can have zero length, thus is always .
Ho wants her student to be strong to all kinds of opponents, so she defines the weakness of student as a maximum value among . A student is a Gosu in Taebo when the weakness of student is minimum among all weakness values. By this definition, there can be multiple Gosu-s.
Since Ho is too old to tell who is Gosu, your task is to find a Gosu and weakness value of Gosu to help Ho. If there exist multiple Gosu-s, you can print any of them.
Input
In the first line, the number of students is given.
In the -th line of the next lines, a string consists of W, L, and -. Let's denote the -th character of as . is given as follows:
-
-, if . -
W, if student won against student . -
L, if student won against student .
Output
Print two space-separated integers, and , where student is Gosu, and is the weakness of student .
If there are multiple answers, you can print any of them.
Constraints
-
-() - If , then
WorL. () - If
W, thenL. () - If
L, thenW. ()