#include<iostream>
#include<stdio.h>
#include<string>
#define MAXN 105
using namespace std;
struct unix
{
string s1;
string s2;
};
bool ck[MAXN];
int _m[MAXN][MAXN];
int match[MAXN];
string rec[MAXN];
unix dev[MAXN];
unix adap[MAXN];
bool mark_adap[MAXN];
int hungary(int a,int b);
int a;
int b;
int c; void For_adap(int i);
void make_map();
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int j;
int u;
int v;
int edge;
cin>>a;
for(i = ; i < a; ++ i)
{
cin>>rec[i];
}
cin>>b;
for(i = ; i < b; ++ i)
{
cin>>dev[i].s1;
cin>>dev[i].s2;
}
cin>>c;
for(i = ; i < c; ++ i)
{
cin>>adap[i].s1;
cin>>adap[i].s2;
}
memset(_m,,sizeof(_m));
make_map();
//for(i = 0; i < b; ++ i)
//{
// for(j = 0; j < a; ++ j)
//. {
//\ if(_m[i][j] == 1)
// cout<<dev[i].s1<<"---->"<<rec[j]<<endl;
// }
//}
cout<<b-hungary(b,a)<<endl;
} void make_map()
{
int i;
int j;
for(i = ; i < b; ++ i)
{
memset(mark_adap,false,sizeof(mark_adap));
for(j = ; j < a; ++ j)
{
if(dev[i].s2 == rec[j])
_m[i][j] = ;
}
For_adap(i);
}
} void For_adap(int i)
{
int j;
int k;
string tem;
for(j = ; j < c; ++ j)
{
if(dev[i].s2 == adap[j].s1 && !mark_adap[j])
{
mark_adap[j] = true;
for(k = ; k < a; ++ k)
{
if(rec[k] == adap[j].s2)
{
_m[i][k] = ;
}
}
tem = dev[i].s2;
dev[i].s2 = adap[j].s2;
For_adap(i);
dev[i].s2 = tem;
}
}
} ///////////////////////////////////////////////////
//hungary—by myself
///////////////////////////////////////////////////
bool search(int a,int b,int x)
{
int i;
int t;
for ( i = ; i < b ; i++)
if (_m[x][i] && ! ck[i])
{
ck[i] = true;
t = match[i];
match[i] = x;
if (t == - || search(a,b,t))
return true;
match[i] = t;
}
return false;
} int hungary(int a,int b)
{
memset(match,-,sizeof(match));
int max_match = ;
int i;
for ( i = ; i < a ; i++)
{
memset(ck,false,sizeof(ck));
if (search(a,b,i)) max_match++;
}
return max_match;
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com