Language: C++

#include<iostream>
#include<vector>
#define INF 999999
#define MAX_V 10000
using namespace std;

typedef struct edge{
  int to,cap,rev;
}edge;

int val[MAX_V];
vector<edge> G[MAX_V];
bool used[MAX_V];

bool gcd(int a,int b){
  int r=a%b;
  while(r>0){
    a=b;
    b=r;
    r=a%b;
  }
  if(b!=1)return true;
  else return false;
}

void makeG(int m,int n){
  memset(G,0,sizeof(G));
  int to;
  for(int i=0;i<m+n;i++){
    cin>>val[i];
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(gcd(val[i],val[m+j])==true){
	G[i].push_back((edge){m+j,1,G[m+j].size()});
	G[m+j].push_back((edge){i,0,G[i].size()-1});
      }
    }
  }
  val[m+n]=val[m+n+1]=1;
  for(int i=0;i<m;i++){
    G[m+n].push_back((edge){i,1,G[i].size()});
    G[i].push_back((edge){m+n,0,G[i].size()-1});
  }
  for(int i=m;i<m+n;i++){
    G[i].push_back((edge){m+n+1,1,G[m+n+1].size()});
    G[m+n+1].push_back((edge){i,0,G[i].size()-1});
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(){
  int m,n;
  while(cin>>m>>n,n){
    makeG(m,n);
    cout << max_flow(m+n,m+n+1) << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'void makeG(int, int)':
a.cc:27:3: error: 'memset' was not declared in this scope
   27 |   memset(G,0,sizeof(G));
      |   ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<vector>
  +++ |+#include <cstring>
    3 | #define INF 999999
a.cc:35:48: warning: narrowing conversion of 'G[(m + j)].std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   35 |         G[i].push_back((edge){m+j,1,G[m+j].size()});
      |                                     ~~~~~~~~~~~^~
a.cc:36:48: warning: narrowing conversion of '(G[i].std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   36 |         G[m+j].push_back((edge){i,0,G[i].size()-1});
      |                                     ~~~~~~~~~~~^~
a.cc:42:42: warning: narrowing conversion of 'G[i].std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   42 |     G[m+n].push_back((edge){i,1,G[i].size()});
      |                                 ~~~~~~~~~^~
a.cc:43:44: warning: narrowing conversion of '(G[i].std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   43 |     G[i].push_back((edge){m+n,0,G[i].size()-1});
      |                                 ~~~~~~~~~~~^~
a.cc:46:48: warning: narrowing conversion of 'G[((m + n) + 1)].std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   46 |     G[i].push_back((edge){m+n+1,1,G[m+n+1].size()});
      |                                   ~~~~~~~~~~~~~^~
a.cc:47:46: warning: narrowing conversion of '(G[i].std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   47 |     G[m+n+1].push_back((edge){i,0,G[i].size()-1});
      |                                   ~~~~~~~~~~~^~
a.cc: In function 'int max_flow(int, int)':
a.cc:71:5: error: 'memset' was not declared in this scope
   71 |     memset(used,0,sizeof(used));
      |     ^~~~~~
a.cc:71:5: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'