您的位置:首页 > 其它

HDU4324-Triangle LOVE-判断是否存在环(拓扑)

2015-11-20 22:22 246 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4324

题目意思:矩阵。1表示i-th喜欢j-th,问是否存在环状喜欢关系。

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=2005;
bool Map

;
int t,n,Case=1;
char str
;
struct node{
int in,out;
}s
;
int TopSort()
{
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(s[j].in==0){
s[j].in=-1;
for(int k=0;k<n;k++){
if(Map[j][k]){
s[k].in--;
}
}
}
}
}
for(int i=0;i<n;i++)
if(s[i].in>0) return 0;
return 1;
}
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(Map,false,sizeof(Map));
memset(s,0,sizeof(s));
for(int i=0;i<n;i++){
scanf("%s",str);
for(int j=0;j<n;j++){
if(str[j]=='1'){
s[i].out++;
s[j].in++;
Map[i][j]=true;
}
}
}
if(!TopSort()) printf("Case #%d: Yes\n",Case++);
else printf("Case #%d: No\n",Case++);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  判断是否存在环