Pro.ID22158 TitleKing Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22158 AC0 Submit9 Ratio0.00% 时间&空间限制描述There are n children in a country marked by integers from 1 to n. They often fight with each other. For each pair of child A and child B, either A beats B or B beats A. It is not possible that both A beats B and B beats A. Of course, one never fight with himself. Child A is not afraid of child B if A can beat B. Child A is not afraid of child B if A can beat C and C can beat B either. Because A can say "I will call C to beat you" to B. A child is called a king of children if he is not afraid of any other child. Give you the beating relations. Find a king. 输入The first line contains a integer n which is between 1 and 1000. The following n lines contains n characters respectively. Character is either '0' or '1'. The B-th character of (A+1)-th line will be '1' if and only if A can beat B. Input is terminated by EOF. 输出Description There are n children in a country marked by integers from 1 to n. They often fight with each other. For each pair of child A and child B, either A beats B or B beats A. It is not possible that both A beats B and B beats A. Of course, one never fight with himself. Child A is not afraid of child B if A can beat B. Child A is not afraid of child B if A can beat C and C can beat B either. Because A can say "I will call C to beat you" to B. A child is called a king of children if he is not afraid of any other child. Give you the beating relations. Find a king. Input The first line contains a integer n which is between 1 and 1000. The following n lines contains n characters respectively. Character is either '0' or '1'. The B-th character of (A+1)-th line will be '1' if and only if A can beat B. Input is terminated by EOF. Output A number representing a king of children on a line. If such a king does not exist, output -1. Sample Input 2 Sample Output 1 Source 样例输入2 样例输出1 作者 |