#include <bits/stdc++.h> using namespace std; const int maxn = 1e2+10; bool G[maxn][maxn]; string l[maxn]; int l1[maxn], l2[maxn]; string r[maxn]; int r1[maxn], r2[maxn]; bool link[maxn][maxn]; bool AT[maxn][maxn]; bool TA[maxn][maxn]; int n, m; int linker[maxn]; bool used[maxn]; void init(){ memset(l1, 0, sizeof(l1)); memset(l2, 0, sizeof(l2)); memset(r1, 0, sizeof(r1)); memset(r2, 0, sizeof(r2)); memset(link, 0, sizeof(link)); memset(AT, 0, sizeof(AT)); memset(TA, 0, sizeof(TA)); } bool dfs(int u){ for(int v=0; v<m; v++){ if(link[u][v]&&!used[v]){ used[v] = true; if(linker[v] == -1||dfs(linker[v])){ linker[v] = u; return true; } } } return false; } int hungry(){ int res = 0; memset(linker, -1, sizeof(linker)); for(int i=0; i<n; i++){ memset(used, 0, sizeof(used)); if(dfs(i)) res++; } return res; } void print_ans(){ for(int i=0; i<m; i++){ if(linker[i]!=-1){ int u = linker[i]; int v = i; if(AT[u][v]){ cout<<"AT"<<" "<<l[u]<<" "<<r[v]<<endl; } else{ cout<<"TA"<<" "<<r[v]<<" "<<l[u]<<endl; } } } } int main() { freopen("Input.txt", "r", stdin); freopen("Output.txt", "w", stdout); init(); ios::sync_with_stdio(false); cin>>n>>m; for(int i=0; i<n; i++){ cin>>l[i]; for(int j=0; j<3; j++){ l1[i] += l[i][j]-'0'; } for(int j=3; j<6; j++){ l2[i] += l[i][j]-'0'; } } for(int i=0; i<m; i++){ cin>>r[i]; for(int j=0; j<3; j++){ r1[i] += r[i][j]-'0'; } for(int j=3; j<6; j++){ r2[i] +=r[i][j]-'0'; } } for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ if(l1[i] == r2[j]){ AT[i][j] = true; link[i][j] = true; } if(l2[i] == r1[j]){ TA[i][j] = true; link[i][j] = true; } } } int tot = hungry(); cout<<tot<<endl; print_ans(); return 0; }
|