If a love triangle exists, the output is yes;
1 indicates that others like him, and add one for others;
Then sort by topology;
As long as there is no point with zero inbound, a love triangle is formed, and yes is output;
# Include "stdio. H"
# Include "string. H"
Int degree [3000];
Char map [3000] [3000];
Int N;
Int posort ()
{
Int I, J, K;
For (I = 0; I <n; I ++)
For (j = 0; j <n; j ++)
If (Map [I] [J] = '1 ')
Degree [J] ++;
For (I = 0; I <n; I ++)
{
J = 0;
While (degree [J]! = 0)
J ++;
If (j = N)
Return 0;
Else
{
Degree [J] --;
For (k = 0; k <n; k ++)
If (Map [J] [k] = '1 ')
Degree [k] --;
}
}
Return 1;
}
Int main ()
{
Int K, I, j, r = 1;
Scanf ("% d", & K );
While (k --)
{
Scanf ("% d", & N );
Memset (degree, 0, sizeof (degree ));
For (I = 0; I <n; I ++)
Scanf ("% s", map [I]);
Printf ("case # % d:", r ++ );
If (! Posort ())
Printf ("Yes \ n ");
Else
Printf ("NO \ n ");
}
Return 0;
}