# Include < Iostream >
# Include < String >
# Include < Map >
# Define Vmax 600
# Define Pymax 800
Using Namespace STD;
Map < String , Int > Item;
Map < String , Int > : Iterator it;
Int N, N2, M, K;
Int Match;
Int Map1 [Pmax] [Pmax] = { 0 }; // Association Diagram
Int MAP2 [Vmax] [Vmax] = { 0 }; // Simplified chart
Int Dev [Vmax]; // Serial number of the plug corresponding to the device
Int Path [Vmax]; // Zengguang Road
Int Link [Vmax] = { 0 }; // Match
Int Addplug ( String Plug) // Add plug type
{
It = Item. Find (plug );
If (It = Item. End ()) // If not found, add
{
Item. insert (pair < String , Int > (Plug, N2 ));
N2 ++ ;
Return N2 - 1 ;
}
Else // Returns the serial number.
Return Item [plug];
}
Int Find ( Int I) // HungaryAlgorithm
{
For ( Int J = 1 ; J <= N; j ++ )
If (MAP2 [I] [J] && ! Path [J]) // I connected to J & J is not on the current augmented path
{
Path [J] = 1 ;
If ( ! Link [J] | Find (link [J])
{
Link [J] = I;
Return 1 ;
}
}
Return 0 ;
}
Int Main ()
{
Int A, B;
Int I, J, K;
String Tmp1, tmp2;
CIN > N;
N2 = N;
For (I = 0 ; I < N; I ++ )
{
CIN > Tmp1;
Item. insert (pair < String , Int > (Tmp1, I ));
}
CIN > M;
For (I = 0 ; I < M; I ++ )
{
CIN > Tmp1 > Tmp2;
Dev [I] = Addplug (tmp2 );
}
CIN > K;
For (I = 0 ; I < K; I ++ )
{
CIN > Tmp1 > Tmp2;
A = Addplug (tmp1 ); // Otherwise, map1 [item [tmp1] [item [tmp2] = 1
B = Addplug (tmp2 );
Map1 [a] [B] = 1 ;
}
For (I = 0 ; I < N2; I ++ )
For (J = 0 ; J < N2; j ++ )
{
If (I = J)
{
Map1 [I] [I] = 1 ;
Continue ;
}
If (Map1 [J] [I])
For (K = 0 ; K < N2; k ++ )
If (Map1 [I] [k])
Map1 [J] [k] = 1 ;
}
For (I = 0 ; I < M; I ++ ) // Constructor
For (J = 0 ; J < N; j ++ )
If (Map1 [Dev [I] [J])
MAP2 [I + 1 ] [J + 1 ] = 1 ;
Match = 0 ;
For (I = 1 ; I <= M; I ++ )
{
Memset (path, 0 , Sizeof (PATH )); // Clear zengguang Road
Match + = Find (I );
}
Printf ( " % D \ n " , M - Match );
Return 0 ;
}