遍历法,超时
package p1;
import java.util.Scanner;
public class t1282 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int r = s.nextInt();
int c = s.nextInt();
int[][] n = new int[r][c];
int[] m = new int[r];
for (int i = 0; i < r; i++) {
m[i] = i;
for (int j = 0; j < c; j++) {
n[i][j] = s.nextInt() - 1;
}
}
s.close();
for (int i = 0; i < 1000000001; i++) {
if (check(m, n, i % c, r)) {
System.out.println(i + 1);
return;
}
}
System.out.println("No one knows.");
}
private static boolean check(int[] m, int[][] n, int d, int r) {
for (int i = 0; i < r; i++) {
m[i] = n[m[i]][d];
}
for (int i = 0; i < r; i++) {
if (i != m[i]) {
return false;
}
}
return true;
}
}