-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path1056.cpp
More file actions
48 lines (48 loc) · 1.36 KB
/
Copy path1056.cpp
File metadata and controls
48 lines (48 loc) · 1.36 KB
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
// Ivan Carvalho
// Solution to https://www.beecrowd.com.br/judge/problems/view/1056
#include <cstdio>
#include <vector>
#define MAXN 210
using namespace std;
int vetor[MAXN], n, m;
vector<int> match, vis, grafo[MAXN];
int Aug(int l) {
if (vis[l]) return 0;
vis[l] = 1;
for (int i = 0; i < (int)grafo[l].size(); i++) {
int r = grafo[l][i];
if (match[r] == -1 || Aug(match[r])) {
match[r] = l;
return 1;
}
}
return 0;
}
int main() {
int casos;
scanf("%d", &casos);
for (int caso = 1; caso <= casos; caso++) {
for (int i = 0; i < MAXN; i++) grafo[i].clear();
match.clear();
vis.clear();
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &vetor[i]);
scanf("%d", &m);
for (int i = n + 1; i <= n + m; i++) scanf("%d", &vetor[i]);
for (int i = 1; i <= n; i++) {
for (int j = n + 1; j <= n + m; j++) {
if (vetor[i] == vetor[j] ||
(vetor[i] != 0 && (vetor[j] % vetor[i]) == 0))
grafo[i].push_back(j);
}
}
int resposta = 0;
match.assign(n + m + 10, -1);
for (int i = 1; i <= n; i++) {
vis.assign(n + 10, 0);
resposta += Aug(i);
}
printf("Case %d: %d\n", caso, resposta);
}
return 0;
}