水题,我竟然把Yes和No写成了YES和NO。。。。。
#include<iostream>
#include<stdio.h>
using namespace std;
int frid[105][105];
int cloth[105];
int n;
int r_right;
void dfs(int m,int c)
{
//cout<<m<<endl;
if(r_right==0)
return;
int j;
for(j=0;j<n;j++)
{
if(frid[m][j])
{
if(cloth[j]==-1)
{
cloth[j]=1-cloth[m];
dfs(j,cloth[j]);
}
else
{
if(cloth[j]!=1-cloth[m])
{
r_right=0;
return;
}
}
}
}
}
int main()
{
while(scanf("%d",&n),n)
{
int i,j;
r_right=1;
memset(cloth,-1,sizeof(cloth));
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&frid[i][j]);
for(i=0;i<n&&r_right;i++)
{
if(cloth[i]==-1)
{
cloth[i]=0;
dfs(i,0);
}
}
if(r_right)
printf("Yes\n");
else
printf("No\n");
}
}