-
Notifications
You must be signed in to change notification settings - Fork 1
/
BPM with Kuhn.cpp
88 lines (82 loc) · 1.65 KB
/
BPM with Kuhn.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//Tested in Lightoj 1149 //
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mem(n) memset(n,0,sizeof(n))
#define LCM(a,b) (a / __gcd(a,b) ) * b
#define gcd(a,b) __gcd(a,b)
#define for0(l,n) for(int l=0;l<n;l++)
#define for1(l,n) for(int l=1;l<=n;l++)
#define bug(n) cout<<">> "<<n<<" <<";
#define pb push_back
#define squerit(n) (ll)n*n
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0)
#define MAX 205
vector<int>v[MAX];
ll n,m,q,a,b,c,sum=0,cnt=0;
//ll arr[1000055];
map<ll,bool>mp;
string s;
int match[MAX];
bool col[MAX];
bool dfs(int nd)
{
int sz = v[nd].size();
for0(i,sz)
{
int u = v[nd][i];
if(!col[u])
{
col[u]=1;
if(match[u]==-1 || dfs(match[u]))
{
match[u]=nd;
return true;
}
}
}
return false;
}
int BPM()
{
memset(match,-1,sizeof(match));
int cnt = 0;
for0(i,n)
{
mem(col);
// col[i]=1;
if(dfs(i))
cnt++;
}
return cnt;
}
int arr[MAX],brr[MAX];
int main()
{
//freopen("output.txt","w",stdout);
FastRead;
int t,cs=1,m,p;
cin>>t;
for(int cs=1;cs<=t;cs++){
cin>>n;
for(int i=0;i<n;i++)
cin>>arr[i];
cin>>m;
for(int i=0;i<m;i++)
cin>>brr[i];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(brr[j]%arr[i]==0)
v[i].pb(j);
}
}
n=n+m;
cout<<"Case "<<cs<<": "<<BPM()<<endl;
for0(i,n)
{
v[i].clear();
}
}
}