Time Limit: 3000MS 

Memory Limit: Unknown 

64bit IO Format: %lld &%llu 
Submit Status
Description
Charge of setting up the Press hostel for the inaugural meeting of the All Nations Internet eXecutive (UNIX), which has a international mandate to make the free flow of information and ideas on the Internet as cumbersome and bureau Cratic as possible.
Since the designed to accommodate reporters and journalists from around the world, it's equipped with electrical Receptacles to suit the different shapes of plugs and voltages used by appliances in all of the countries that existed wh En the hostel was built. Unfortunately, the built many years ago when reporters used very few electric and electronic devices and is equip PED with only one receptacle of each type. These days, like everyone else, reporters require many such devices to do their jobs:laptops, cell phones, tape recorders , pagers, coffee pots, microwave ovens, blow dryers, curling irons, tooth brushes, etc. Naturally, many of these devices can operate on batteries, but since the meeting was likely to being long and tedious, you wan T to is able to plug in as many as can.
Before the meeting begins, you gather up all the devices so the reporters would liketouse, and attempttoset them up. You notice this some of the devices use plugs for which there are no receptacle. You wonder if these devices is from countries this didn ' t exist when the the hostel was built. For some receptacles, there is several devices that use the corresponding plug. For other receptacles, there is no devices that use the corresponding plug.
In order to try to solve the problem you visit a nearby parts supply store. The store sells adapters that allow one type of plug to be used in a different type of outlet. Moreover, adapters is allowed to being plugged into other adapters. The store does not has adapters for all possible combinations of plugs and receptacles, but there was essentially an unlim ited supply of the ones they do has.
InputThe input would consist of several case. The first line of the input contains the number of cases, and it's followed bya blank line. The first line of all case contains a single positive integer
N() indicating the number of receptacles in the. The next
NLines list the receptacle types found in the. Each receptacle type consists of a string of in most alphanumeric characters. The next line contains a single positive integer
m() indicating the number of devices you would like to plug in. Each of the next
mLines lists the name of a device followed by the type of plug it uses (which are identical to the type of receptacle it req Uires). A device name is a string of alphanumeric characters. No. Devices would have exactly the same name. The plug type is separated from the device name by a space. The next line contains a single positive integer
k() indicating the number of different varieties of adapters that is available. Each of the next
kLines describes a variety of adapter, giving the type of receptacle provided by the adapter, followed by a space, followed By the type of plug.
There ' s a blank line between test cases.
OutputFor each case, print a line containing a single nonnegative integer indicating the smallest number of devices that cannot is plugged in. Print a blank line between cases.
Sample Input
14abcd5laptop Bphone cpager bclock bcomb x3b XX AX D
Sample Output
1
Miguel A. Revilla
20000209
Source
Root:: AOAPC i:beginning algorithm Contests (Rujia Liu):: Volume 7. Graph Algorithms and implementation techniques
Root:: Competitive programming:increasing The Lower Bound of programming contests (Steven & Felix Halim):: Chapter 4. Graph:: Special graphbipartite Graph:: Max cardinality bipartite Matching
Root:: AOAPC ii:beginning algorithm Contests (Second Edition) (Rujia Liu):: Chapter 11. Graph Theory:: Examples
Root:: Competitive programming 2:this increases the lower bound of programming contests. Again (Steven & Felix Halim):: Graph:: Maximum Flow:: Standard
Root:: Competitive programming 3:the New Lower Bound of programming contests (Steven & Felix Halim):: Graph:: Spec Ial Graphs (Others):: bipartite Graph
Test instructions: input n, there are n sockets, the following n line is the type of each socket (the last 24 letters to indicate a socket, no spaces at ease with the scanf, but it is possible that the socket will be the same, but this has no effect)
Input m, there are m electrical appliances, the following m line of two words per line is the name of the appliance and the plug type (the same 24 letter word inside no space, two words separated by space)
Input k, there are K converters, the following K lines per line of two words, respectively, the converter's entry type and plug type
The number of each converter is infinite, and the converter itself can be connected to the converter
To ask you, so that the largest number of appliances can be plugged into the socket (can be assisted by the converter can also be directly plugged in), output can not be plugged in the quantity of electrical appliances
s with all electrical appliances to build a forward edge, capacity of 1, all sockets and sinks to build a forward edge, capacity of 1. For each appliance, if it can be connected directly to the socket, and each can be connected to a socket to build a forward edge, Capacity is 1. In addition, all electrical appliances and all can be connected to the converter to build a forward edge, a capacity of 1, the converter and the converter can be connected between the building of a forward edge capacity of the INF, converters and sockets can be connected to build a forward edge capacity of 1.
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;int head[int (1e3)],tail;struct edge{int From,to,next,cap,flow;} Edge[int (1e6)];void Add (int from,int to,int cap,int flow) {edge[tail].from=from;edge[tail].to=to;edge[tail].cap=cap; edge[tail].flow=flow;edge[tail].next=head[from];head[from]=tail++;} int Up[int (1E3)],path[int (1E3)];int work (int ed) {Int. Ans=0;while (1) {Queue<int>qq;memset (up,0,sizeof (UP)); memset (Path), Up[0]=int_max;qq.push (0), while (Qq.size ()) {INT From=qq.front (), Qq.pop (); for (INT i= Head[from];i!=1;i=edge[i].next) if (up[edge[i].to]==0&&edge[i].cap>edge[i].flow) {path[edge[i].to]=i; Qq.push (edge[i].to); Up[edge[i].to]=min (up[from],edge[i].capedge[i].flow);}} if (up[ed]==0) return ans;ans+=up[ed];for (int i=path[ed];i!=1;i=path[edge[i].from]) {edge[i].flow+=up[ed];edge[i^1 ].flow=up[ed];}}} String Rp[110],dv[110][2],ap[110][2];int Main () {int T;cin>>t;while (t) {int n;cin>>n;for (int i=0;i<n ; i++) cin>>rp[i];int m;cin>>m;for (int i=0;i<m;i++) for (int j=0;j<2;j++) Cin>>dv[i][j];int k; cin>>k;for (int i=0;i<k;i++) for (int j=0;j<2;j++) Cin>>ap[i][j];tail=0;memset (head,1,sizeof (head )), for (int i=0;i<m;i++) {Add (0,n+i+1,1,0), add (n+i+1,0,0,0), for (int j=0;j<n;j++) if (Dv[i][1]==rp[j]) {Add (n+1+ i,1+j,1,0); add (1+j,n+1+i,0,0);} for (int j=0;j<k;j++) if (Dv[i][1]==ap[j][0]) {Add (n+1+i,n+m+1+j,1,0); add (n+m+1+j,n+1+i,0,0);}} for (int i=0;i<k;i++) {for (int j=0;j<k;j++) if (Ap[i][1]==ap[j][0]) {Add (n+m+1+i,n+m+1+j,int_max,0); Add (n+m+1+j , n+m+1+i,0,0);} for (int j=0;j<n;j++) if (Ap[i][1]==rp[j]) {Add (n+m+1+i,1+j,1,0); add (1+j,n+m+1+i,0,0);}} for (int i=0;i<n;i++) {Add (1+i,n+m+k+1,1,0); Add (n+m+k+1,1+i,0,0);} Cout<<mwork (n+m+k+1) <<endl;if (T) Cout<<endl;}}
UVA753 A Plug for UNIX