func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T, typename C>   class mcmf {    public:     static constexpr T eps = (T)1e-9;     struct edge {       int from;       int to;       T c;       T f;       C cost;     };     vector<vector<int> > g;     vector<edge> edges;     vector<C> d;     vector<int> q;     vector<bool> in_queue;     vector<int> pe;     int n;     int st, fin;     T flow;     C cost;     mcmf(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) {       assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);       g.resize(n);       d.resize(n);       in_queue.resize(n);       pe.resize(n);       flow = 0;       cost = 0;     }     void clear_flow() {       for (const edge &e : edges) {         e.f = 0;       }       flow = 0;     }     void add(int from, int to, T forward_cap, T backward_cap, C cost) {       assert(0 <= from && from < n && 0 <= to && to < n);       g[from].push_back((int)edges.size());       edges.push_back({from, to, forward_cap, 0, cost});       g[to].push_back((int)edges.size());       edges.push_back({to, from, backward_cap, 0, -cost});     }     bool expath() {       fill(d.begin(), d.end(), numeric_limits<C>::max());       q.clear();       q.push_back(st);       d[st] = 0;       in_queue[st] = true;       int beg = 0;       bool found = false;       while (beg < (int)q.size()) {         int i = q[beg++];         if (i == fin) {           found = true;         }         in_queue[i] = false;         for (int id : g[i]) {           const edge &e = edges[id];           if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) {             d[e.to] = d[i] + e.cost;             pe[e.to] = id;             if (!in_queue[e.to]) {               q.push_back(e.to);               in_queue[e.to] = true;             }           }         }       }       if (d[fin] >= 0) found = 0;       if (found) {         T push = numeric_limits<T>::max();         int v = fin;         while (v != st) {           const edge &e = edges[pe[v]];           push = min(push, e.c - e.f);           v = e.from;         }         v = fin;         while (v != st) {           edge &e = edges[pe[v]];           e.f += push;           edge &back = edges[pe[v] ^ 1];           back.f -= push;           v = e.from;         }         flow += push;         cost += push * d[fin];       }       return found;     }     pair<T, C> max_flow_min_cost() {       while (expath()) {       }       return make_pair(flow, cost);     }   };   const int MG1 = 1e5;   int n1, n2, m, r, b;   string s1, s2;   int eu[200], ev[200], er[200];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n1 >> n2 >> m >> r >> b >> s1 >> s2;     mcmf<int, int> a(n1 + n2 + 2, n1 + n2, n1 + n2 + 1);     memset(er, -1, sizeof(er));     for (int i = 0, j = 0; i < m; ++i) {       cin >> eu[i] >> ev[i], --eu[i], --ev[i];       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  U ) continue;       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  R ) {         a.add(n1 + n2, n1 + ev[i], 1, 0, r);         er[i] = j++;         continue;       }       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  B ) {         a.add(n1 + ev[i], n1 + n2 + 1, 1, 0, b);         er[i] = j++;         continue;       }       if (s1[eu[i]] ==  R  && s2[ev[i]] ==  U ) {         a.add(eu[i], n1 + n2 + 1, 1, 0, r);         er[i] = j++;         continue;       }       if (s1[eu[i]] ==  B  && s2[ev[i]] ==  U ) {         a.add(n1 + n2, eu[i], 1, 0, b);         er[i] = j++;         continue;       }       a.add(eu[i], n1 + ev[i], 1, 0, r);       a.add(n1 + ev[i], eu[i], 1, 0, b);       er[i] = j;       j += 2;     }     int tmg = 0;     for (int i = 0; i < n1; ++i) {       if (s1[i] ==  R ) {         a.add(n1 + n2, i, 1, 0, -MG1);         a.add(n1 + n2, i, 200, 0, 0);         tmg -= MG1;       } else if (s1[i] ==  B ) {         a.add(i, n1 + n2 + 1, 1, 0, -MG1);         a.add(i, n1 + n2 + 1, 200, 0, 0);         tmg -= MG1;       }     }     for (int i = 0; i < n2; ++i) {       if (s2[i] ==  R ) {         a.add(n1 + i, n1 + n2 + 1, 1, 0, -MG1);         a.add(n1 + i, n1 + n2 + 1, 200, 0, 0);         tmg -= MG1;       } else if (s2[i] ==  B ) {         a.add(n1 + n2, n1 + i, 1, 0, -MG1);         a.add(n1 + n2, n1 + i, 200, 0, 0);         tmg -= MG1;       }     }     pair<int, int> p = a.max_flow_min_cost();     int cost = p.second - tmg;     if (cost >= MG1) {       cout << -1;       return 0;     }     cout << cost <<   n ;     for (int i = 0; i < m; ++i) {       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  U ) {         cout <<  U ;         continue;       }       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  R ) {         if (a.edges[2 * er[i]].f)           cout <<  R ;         else           cout <<  U ;         continue;       }       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  B ) {         if (a.edges[2 * er[i]].f)           cout <<  B ;         else           cout <<  U ;         continue;       }       if (s1[eu[i]] ==  R  && s2[ev[i]] ==  U ) {         if (a.edges[2 * er[i]].f)           cout <<  R ;         else           cout <<  U ;         continue;       }       if (s1[eu[i]] ==  B  && s2[ev[i]] ==  U ) {         if (a.edges[2 * er[i]].f)           cout <<  B ;         else           cout <<  U ;         continue;       }       if (a.edges[2 * er[i]].f)         cout <<  R ;       else if (a.edges[2 * (er[i] + 1)].f)         cout <<  B ;       else         cout <<  U ;     }   }   