// If you do not know what the tragedy is, Please split the array into one in question a and let me go!
# Include <iostream> <br/> # include <cstdio> <br/> # include <memory. h> <br/> # include <vector> <br/> # include <string> <br/> # include <map> <br/> # include <queue> </ p> <p> using namespace STD; <br/> struct device {<br/> string name, plug; <br/>}; <br/> struct adapter {<br/> string face, back; <br/>}; <br/> const int max = 105, size = 210, INF = 1 <30; <br/> int n, m, K, start, end, <br/> A [size], pa [size], <br/> flow [size] [siz E], Cap [size] [size], uvertex; </P> <p> vector <string> L; <br/> string plug [Max * max]; <br/> device Dev [Max]; <br/> adapter Ada [Max]; <br/> Map <string, bool> vis; <br/> queue <int> q; </P> <p> void DFS (const string & S) {<br/> for (INT I = 0; I <K; I ++) {<br/> If (Ada [I]. back = s) {<br/> If (! VIS. count (Ada [I]. face) {<br/> vis [Ada [I]. face] = 1; <br/> for (Int J = 0; j <m; j ++) {<br/> If (Ada [I]. face = Dev [J]. plug) {<br/> CAP [start] [uvertex] = 1; <br/> CAP [uvertex] [n + 1 + J] = 1; <br/> CAP [n + 1 + J] [end] = 1; <br/>}< br/> DFS (Ada [I]. face); <br/>}< br/> return; <br/>}< br/> void creategraph () {<br/> string s; <br/> for (INT I = 0; I <n; I ++) {<br/> vis. clear (); <br/> S = plug [I]; <br/> vis [s] = 1; <br/> uvertex = I + 1; <br/> for (INT I = 0; I <m; I ++) {<br/> If (S = Dev [I]. plug) {<br/> CAP [start] [uvertex] = 1; <br/> CAP [uvertex] [n + 1 + I] = 1; <br/> CAP [n + 1 + I] [end] = 1; <br/>}< br/> DFS (s ); <br/>}< br/> return; <br/>}</P> <p> int maxflow () {<br/> int f = 0, U, v; <br/> memset (flow, 0, sizeof (flow); <br/> while (1) {<br/> memset (A, 0, sizeof (a); <br/> A [start] = inf; <br/> q. push (start); <br/> while (! Q. empty () {<br/> U = Q. front (); q. pop (); <br/> for (V = 0; v <End + 1; V ++) {<br/> If (! A [v] & Cap [u] [v]> flow [u] [v]) {<br/> A [v] = A [u] <(Cap [u] [v]-flow [u] [v])? <Br/> A [u] :( CAP [u] [v]-flow [u] [v]); <br/> pa [v] = u; <br/> q. push (V); <br/>}< br/> If (! A [end]) <br/> break; <br/> for (u = end; u! = Start; u = pa [u]) {<br/> flow [u] [PA [u]-= A [end]; <br/> flow [PA [u] [u] + = A [end]; <br/>}< br/> // cout <A [end] <Endl; <br/> F + = A [end]; <br/>}< br/> return F; <br/>}< br/> int main () <br/>{< br/> freopen ("I .txt ", "r", stdin); <br/> int ncase, num = 0; <br/> CIN> ncase; <br/> Start = 0; <br/> while (ncase --) {<br/> If (Num ++) <br/> cout <Endl; <br/> CIN> N; <br/> L. clear (); <br/> for (INT I = 0; I <n; I ++) {<br/> CIN> plug [I]; <br/>}< br/> CIN> m; <br/> end = N + m + 1; <br/> for (INT I = 0; I <m; I ++) <br/> CIN> Dev [I]. name> Dev [I]. plug; </P> <p> CIN> K; <br/> for (INT I = 0; I <K; I ++) <br/> CIN> Ada [I]. face> Ada [I]. back; <br/> memset (Cap, 0, sizeof (CAP); <br/> creategraph (); <br/>/* For (INT I = 0; I <End + 1; I ++) {<br/> for (Int J = 0; j <= end + 1; j ++) {<br/> If (Cap [I] [J] = 1) <br/> cout <I <"" <j <Endl; <br/>}< br/>} */<br/> cout <m-maxflow () <Endl; <br/> // cout <Endl; <br/>/* For (INT I = 0; I <End + 1; I ++) {<br/> for (Int J = 0; j <= end + 1; j ++) {<br/> If (flow [I] [J] = 1) <br/> cout <I <"" <j <Endl; <br/>}< br/>}*/<br/> // cout <Endl; <br/> // cout <flow [33] [193] <Endl; <br/> // cout <CAP [33] [193] <Endl; <br/>}< br/> return 0; <br/>}< br/>