Gosu

Time limit1sMemory limit1024 MB

Summary
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 NN 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 N(N−1)2\frac{N(N-1)}{2} 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 xx to player yy be a sequence of K+1K+1 integers a_0=x, a_1, ⋯ , a_K=ya\_0 = x,\ a\_1,\ \cdots ,\ a\_K = y, where student a_ia\_i has won against student a_i+1a\_{i+1} for all 0≤i<K0 \le i < K. We call KK the length of this winning path. For example, if there exists a winning path of length 1, we can immediately know that xx has won against student yy. If there exists a winning path of length 2, then xx may not have won against yy directly, but there exists some other player zz that xx has won against, and zz has won against yy.

The distance d(x, y)d(x,\ y) is defined as a minimum length of a winning path from xx to yy, if such exists. There could be a case that xx cannot 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 kinds of opponents, so she defines the 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 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

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

In the ii-th line of the next NN lines, a string s_is\_i consists of W, L, and -. Let's denote the jj-th character of s_is\_i as s_i,js\_{i,j}. s_i,js\_{i,j} is given as follows:

  • s_i,j=s\_{i,j}= -, if i=ji=j.
  • s_i,j=s\_{i,j}= W, if student ii won against student jj.
  • s_i,j=s\_{i,j}= L, if student jj won against student ii.

Output

Print two space-separated integers, d{\color{red}d} and u{\color{red}u}, where student uu is Gosu, and dd is the weakness of student uu.

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

Constraints

  • 2≤N≤3 0002 \le N \le 3\,000
  • s_i,i=s\_{i, i} = - (1≤i≤N1 \le i \le N)
  • If i≠ji \neq j, then s_i,j=s\_{i, j}= W or s_i,j=s\_{i, j}= L. (1≤i≤N1 \le i \le N)
  • If s_i,j=s\_{i, j} = W, then s_j,i=s\_{j, i} = L. (1≤i, j≤N1 \le i,\ j \le N)
  • If s_i,j=s\_{i, j} = L, then s_j,i=s\_{j, i} = W. (1≤i, j≤N1 \le i,\ j \le N)

Examples3

  1. Example 1

    Input
    2
    -W
    L-
    Expected output
    1 1
  2. Example 2

    Input
    3
    -LW
    W-L
    LW-
    Expected output
    2 1
  3. Example 3

    Input
    5
    -WLLW
    L-LLW
    WW-LL
    WWW-W
    LLWL-
    Expected output
    1 4