You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
914 B
36 lines
914 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define inf 0x3f3f3f3f
|
|
const int N = 510;
|
|
int n, m, x, y, ans;
|
|
int g[N][N];
|
|
|
|
void floyd() {
|
|
for (int k = 1; k <= n; k++)
|
|
for (int i = 1; i <= n; i++) {
|
|
if (!g[i][k]) continue; // floyd优化
|
|
for (int j = 1; j <= n; j++)
|
|
g[i][j] |= g[i][k] & g[k][j]; // 通过k传递,或运算
|
|
}
|
|
}
|
|
int main() {
|
|
int T;
|
|
cin >> T;
|
|
while (T--) {
|
|
cin >> n >> m;
|
|
memset(g, 0, sizeof g);
|
|
while (m--) {
|
|
cin >> x >> y;
|
|
g[x][y] = 1; // x<y
|
|
}
|
|
// 计算传递闭包
|
|
floyd();
|
|
|
|
ans = 0;
|
|
for (int i = 1; i <= n; i++) // 统计答案
|
|
for (int j = i + 1; j <= n; j++)
|
|
if (!g[i][j] && !g[j][i]) ans++; // 无法确定大小关系
|
|
cout << ans << endl;
|
|
}
|
|
return 0;
|
|
} |