intmain(){ int t; cin >> t; for (int i0 = 0; i0 < t; i0++) { int n, m; cin >> n >> m; int arr[maxN][maxN] = { 0 }; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; arr[a][b] = 1; } // Floyd 算法 for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (arr[j][i] == 1)//已知道了两人关系 再进行更新第三人 for (int k = 1; k <= n; k++) if (arr[i][k] == 1) arr[j][k] = 1; int count = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j && arr[i][j] == 0 && arr[j][i] == 0) count++; cout << count / 2 << endl;// i 求了一遍,j 又求了一遍,所以要减半 } return0; }