参考抄袭大佬思路:双map当作两个相邻帧,开始还想着字符串匹配,kmp,dp之类的。

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n > 0) {
            n--;
            int cnt;
            Map<String, Integer> map1 = new HashMap<>();
            int m = scanner.nextInt();
            if(m>0){
                cnt=1;
            }else{
                cnt=0;
            }
            for(int i = 0; i < m; i++){
                int t = scanner.nextInt();
                int[][] temp = new int[t][2];
                Map<String, Integer> mapNow = new HashMap<>();
                for(int j = 0; j < t; j++){ //对1行处理
                    temp[j][0] = scanner.nextInt();
                    temp[j][1] = scanner.nextInt();
                    if(map1.containsKey(temp[j][0] + "," + temp[j][1])){
                        int cntTemp = map1.get(temp[j][0] + "," + temp[j][1]) + 1;
                        mapNow.put(temp[j][0] + "," + temp[j][1], cntTemp);
                        cnt = Math.max(cntTemp, cnt);
                    }else{
                        mapNow.put((temp[j][0] + "," + temp[j][1]), 1);
                    }
                }
                map1 = mapNow;
            }
            System.out.println(cnt);
        }
    }
}