I wrote wa many times for a long time.
Later, I asked you to stay on the stars.
The topic means that you need to use and check the set and then perform enumeration like Vertex coloring. It is very simple to enumerate, but the brute force will not have to re-learn.
The Code is as follows:
# Include <iostream>
Using namespace STD;
Bool hash [20] [20];
Long root [20];
Long n, m;
Bool finish;
Void DFS (long M, long s)
{
If (finish) // you can allocate
{
Return;
}
If (S> m) // too many balls are used
{
Return;
}
If (M = N) // The person has been added
{
Finish = true; // The ball is finished before it is fully split.
Return;
}
Int I, j, FG;
For (I = 0; I <m; I ++)
{
If (root [I]! = I) // If the I-th individual is not a collection representative
Continue; // continue to find the Representative
Fg = 1;
For (j = I; j <M & FG; j ++)
Fg =! (Root [J] = I & (hash [m] [J] = 0 | hash [J] [m] = 0 )); // if no one in the set where I is located rejects m
If (FG)
{
Root [m] = I; // make m belong to the I set
DFS (m + 1, S); // Add another person
Root [m] = m; // M restore continues to enumerate the next set
}
}
DFS (m + 1, S + 1); // when the next person adds one more ball
}
Bool check ()
{
Long I;
Finish = false;
For (I = 0; I <n; ++ I)
{
Root [I] = I;
}
DFS (0, 0 );
If (finish)
{
Return true;
}
Return false;
}
Int main ()
{
While (scanf ("% LD % lD", & N, & M )! = EOF)
{
Memset (hash, 0, sizeof (hash ));
Long I, J;
For (I = 0; I <n; ++ I)
{
Long N;
Scanf ("% lD", & N );
For (j = 0; j <n; ++ J)
{
Long T;
Scanf ("% lD", & T );
Hash [I] [T] = true;
}
}
If (n <= M | check ())
{
Puts ("yes ");
}
Else
{
Puts ("no ");
}
}
Return 0;
}