题目地址:
分析:
搜索
代码:
#include <cstdio>
#include <cstring>
bool graph[1001][1001];
int main(){
int t,n,m,a,b;
bool trans = true;
scanf("%d",&t);
for(int i = 0;i < t;i++){
trans = true;
scanf("%d%d",&n,&m);
memset(graph,0,sizeof(graph));
for(int j = 0;j < m;j++){
scanf("%d%d",&a,&b);
graph[a][b] = true;
}
for(int x = 1;x <= n;x++)
for(int y = 1;y <= n;y++)
if(graph[x][y] && x!=y)
for(int z = 1;z <= n;z++)
if(graph[y][z])
if(!graph[x][z]){
trans = false;
break;
}
if(trans)printf("Yes\n");
else printf("No\n");
}
return 0;
}