第二题:
import java.util.HashMap;
import java.util.Scanner;
import java.util.Map.Entry;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int m = Integer.parseInt(scan.nextLine());
int n = Integer.parseInt(scan.nextLine());
HashMap<String, Integer> map = new HashMap<>();
int max = 0;
for (int i = 0; i < n; i++) {
String[] strs = scan.nextLine().split(" ");
int k = Integer.parseInt(strs[0]);
if (k > 0) {
String[] zus = new String[k];
for (int j = 0; j < k; j++) {
StringBuilder sb = new StringBuilder();
sb.append(strs[2 * j + 1]);
sb.append(strs[2 * j + 2]);
zus[j] = sb.toString();
}
if (map.size() == 0) {
for (int j = 0; j < zus.length; j++) {
map.put(zus[j], 1);
}
} else {
HashMap<String, Integer> map2 = new HashMap<>();
for (Entry<String, Integer> entry : map.entrySet()) {
int nums = entry.getValue();
for (int j = 0; j < zus.length; j++) {
if (entry.getKey().equals(zus[j])) {
nums++;
if (nums > max)
max = nums;
map2.put(entry.getKey(), nums);
break;
}
}
}
map = new HashMap<>(map2);
}
} else {
map = new HashMap<>();
}
}
if (max <= 1)
System.out.println(1);
else
System.out.println(max);
}
}