#P15630. [2019 KAIST RUN Spring] Gosu

[2019 KAIST RUN Spring] Gosu

Problem Description

Ho is an expert in martial arts called Taebo\textit{Taebo}. She runs a Taebo school, and there are NN students in her school. Since Ho is too old to teach Taebo, she is going to hand over her school to one of her students. To find a suitable candidate, Ho made all N(N1)2\frac{N(N-1)}{2} pairs of students do a Taebo matchup with each other, and wrote all the results. In a Taebo matchup, exactly one person wins the match, and another person loses the match. Ho thinks that a student is good enough to receive her school if the student is a Gosu\textbf{Gosu} of Taebo.

Gosu\textbf{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's define a winning path\textbf{winning path} from player xx to player yy as a sequence of K+1K+1 integers a0=x, a1, , aK=ya_0 = x,\ a_1,\ \cdots ,\ a_K = y, where student aia_i has won student ai+1a_{i+1} for all 0i<K0 \le i < K. We call KK as the length\textbf{length} of this winning path. For example, if there exists a winning path\textit{winning path} of length 1, we can immediately know that xx has won student yy. If there exists a winning path of length 2, then xx may not win yy directly, but there exists some other player zz that xx has won, and has won yy.

The distance\textbf{distance} d(x, y)d(x,\ y) is defined as a minimum length of winning path from xx to yy, if such exists. There could be a case that xx can not find a winning path to yy. In that case, we define d(x, y)=9000d(x,\ y) = 9000. Note that, the path can have zero length, thus d(i, i)d(i,\ i) is always 00.

Ho wants her student to be strong to all kind of opponents, so she defines the weakness\textbf{weakness} of student ii, as a maximum value among d(i, 1), d(i, 2), , d(i, N)d(i,\ 1),\ d(i,\ 2),\ \cdots,\ d(i,\ N). A student ii is a Gosu\textbf{Gosu} in Taebo when the weakness of student ii 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 Format

In the first line, the number of students NN is given.

In the ii-th line of next NN lines, a string sis_i consists of W\texttt{W}, L\texttt{L}, and -\texttt{-}. Let's denote jj-th character of sis_i as si,js_{i,j}. si,js_{i,j} is given as follows:

  • si,j=s_{i,j}= -\texttt{-}, if i=ji=j.
  • si,j=s_{i,j}= W\texttt{W}, if student ii won student jj.
  • si,j=s_{i,j}= L\texttt{L}, if student jj won student ii.

  • 2N30002 \le N \le 3\,000
  • si,i=s_{i, i} = -\texttt{-} (1iN1 \le i \le N)
  • If iji \neq j, then si,j=s_{i, j}= W\texttt{W} or si,j=s_{i, j}= L\texttt{L}. (1iN1 \le i \le N)
  • If si,j=s_{i, j} = W\texttt{W}, then sj,i=s_{j, i} = L\texttt{L}. (1i, jN1 \le i,\ j \le N)
  • If si,j=s_{i, j} = L\texttt{L}, then sj,i=s_{j, i} = W\texttt{W}. (1i, jN1 \le i,\ j \le N)

Output Format

Print two space-separated integers, dd and uu, where student uu is Gosu, and dd is weakness of student uu.

If there are multiple answers, you can print any of them.

2
-W
L-
1 1
3
-LW
W-L
LW
2 1
5
-WLLW
L-LLW
WW-LL
WWW-W
LLWL
1 4