Poj 1087 a plug for Unix (max Stream)

Source: Internet
Author: User
Tags alphanumeric characters
A plug for Unix
Time limit:1000 ms   Memory limit:65536 K
Total submissions:11636   Accepted:3834

Description

You are in charge of setting up the press room for the inaugural meeting of the United Nations Internet Executive (UNIX ), which has an international mandate to make the free flow of information and ideas on the Internet as cumbersome and bureaucratic as possible.
Since the room was designed to accommodate reporters and journalists from around the world, it is equipped with electrical appliances tacles to suit the different shapes of plugs and voltages used by appliances in all of the countries that existed when the room was built. unfortunately, the room was built policyears ago when reporters used very few electric and electronic devices and is equipped with only one primary tacle of each type. these days, like everyone else, reporters require login such devices to do their jobs: laptops, cell phones, tape recorders, pagers, coffee pots, microwave ovens, blow dryers, curling
Irons, tooth brushes, etc. naturally, thanks of these devices can operate on batteries, but since the meeting is likely to be long and tedious, you want to be able to plug in as ready as you can.
Before the meeting begins, you gather up all the devices that the reporters wocould like to use, and attempt to set them up. you notice that some of the devices use plugs for which there is no such tacle. you wonder if these devices are from countries that didn't exist when the room was built. for some sort tacles, there are several devices that use the corresponding plug. for other extends tacles, there are 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 are allowed to be plugged into other adapters. the store does not have adapters for all possible combinations of plugs and receptacles, but there is essential an unlimited supply of the ones they do have.

Input

The input will consist of one case. the first line contains a single positive integer N (1 <= n <= 100) indicating the number of specified tacles in the room. the next n lines list the specified tacle types found in the room. each role tacle type consists of a string of at most 24 alphanumeric characters. the next line contains a single positive integer m (1 <= m <= 100) indicating the number of devices you wowould like to plug in. each of the next M lines lists the name of a device followed by the type of plug it uses (which is identical to the type of each tacle it requires ). A device name is a string of at most 24 alphanumeric
Characters. no two devices will 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 (1 <= k <= 100) indicating the number of different varieties of adapters that are available. each of the next K lines describes a variety of adapter, giving the type of role tacle provided by the adapter, followed by a space, followed by the type of plug.

Output

A line containing a single non-negative integer indicating the smallest number of devices that cannot be plugged in.

Sample Input

 
4 a B c d 5 laptop B phone c pager B clock B comb x 3 B x A x D

Sample output

 
1

Source

East central North America 1999
# Include <stdio. h># Include <Map> # Include <Iostream> # Include < String . H> # Include < String > # Include <Queue> Using   Namespace  STD;  //  **************************************** ************  // Maximum stream Template  //  Initialization: G [] [], start, end  //  **************************************** **************  Const   Int Maxn = 500  ;  Const   Int INF = 0x3fffffff  ;  Int G [maxn] [maxn]; // Storage edge capacity, initialization of no edge is 0  Int  Path [maxn], flow [maxn], start, end;  Int N; //  Number of vertex. The value 0-n.n contains the Source Vertex and sink vertex.  Queue < Int > Q;  Int  BFS (){  Int  I, T;  While (! Q. Empty () Q. Pop (); // Clear a queue Memset (path ,- 1 , Sizeof (PATH )); //  Initialize the path to-1 before each search. Path [start] = 0  ; Flow [start] = Inf; //  The source point can have endless streams  Q. Push (start );  While (! Q. Empty () {T = Q. Front (); q. Pop (); If (T = end) Break  ;  //  Enumerate all vertices. If the starting point of the vertex number changes, you can change it here.          For (I = 0 ; I <= N; I ++ ){  If (I! = Start & path [I] =- 1 && G [T] [I]) {flow [I] = Flow [T] <G [T] [I]? Flow [T]: G [T] [I]; q. Push (I); path [I] =T ;}}}  If (Path [end] =- 1 ) Return - 1 ; //  The sink cannot be found. No augmented path found      Return  Flow [end];}  Int  Edmonds_karp (){  Int Max_flow = 0  ;  Int Step, now, pre;  While (Step = BFS ())! =- 1  ) {Max_flow + = Step; now = End;  While (Now! = Start) {pre = Path [now]; G [pre] [now] -= Step; G [now] [pre] + = Step; now = Pre ;}} Return  Max_flow;} Map < String , Int > Hash;  Int  Main (){  //  Freopen ("in.txt", "r", stdin );  //  Freopen ("out.txt", "W", stdout );      String  Str1, str2;  Int  N, m; Int  Tol;  While (Scanf ( "  % D  " , & N )! = EOF) {hash. Clear (); memset (G,  0 , Sizeof  (G); Start = 0  ; End = 1  ; Tol = 2 ;  While (N -- ) {CIN > Str1; hash [str1] = Tol; G [  0 ] [Tol] = 1  ; Tol ++ ;} Scanf (  "  % D  " ,& M );  For (Int I = 0 ; I <m; I ++ ) {CIN >>> Str1 >>> Str2;  If (Hash [str1] = 0 ) Hash [str1] = tol ++ ;  If (Hash [str2] = 0 ) Hash [str2] = tol ++ ; G [hash [str1] [end] = 1  ; G [hash [str2] [hash [str1] =1  ;} Scanf (  "  % D  " ,& N );  While (N -- ) {CIN >>> Str1 >>> Str2;  If (Hash [str1] = 0 ) Hash [str1] = tol ++ ;  If (Hash [str2] = 0 ) Hash [str2] = tol ++ ; G [hash [str2] [hash [str1] = INF;} n = TOL- 1  ; Printf (  "  % D \ n  " , M- Edmonds_karp ());}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.