Minimum overwrite... This is a bidirectional graph.
Typical minimum vertex overwrite! Minimum vertex overwrite = maximum matching (bidirectional graph)/2;
This question has a small detail. The data is large. We need to use an adjacent table. Otherwise, it will time out!
[Csharp]
# Include "stdio. h"
# Include "string. h"
Int map [1501] [1501], mark [1501];
Int link [1501], v [1501];
Int n;
Int dfs (int k)
{
Int I;
For (I = 0; I <n; I ++)
{
If (map [k] [I] = 1 &&! V [I])
{
V [I] = 1;
If (link [I] = 0 | dfs (link [I])
{
Link [I] = k;
Return 1;
}
}
}
Return 0;
}
Int main ()
{
Int I, j, t, a, B, count;
While (scanf ("% d", & n )! =-1)
{
Memset (map, 0, sizeof (map ));
For (I = 0; I <n; I ++)
{
Scanf ("% d :( % d)", & a, & t );
For (j = 0; j <t; j ++)
{
Scanf ("% d", & B );
Map [a] [B] = 1;
Map [B] [a] = 1;
}
}
Count = 0;
Memset (link, 0, sizeof (link ));
For (I = 0; I <n; I ++)
{
Memset (v, 0, sizeof (v ));
If (dfs (I ))
Count ++;
}
Printf ("% d \ n", count/2 );
}
Return 0;
}
Author; yyf572132811