A Plug for UNIX
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 13855 |
|
Accepted: 4635 |
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 like-to-use, and attempt-to-set 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.
Input
The input would consist of one case. The first line contains a, positive integer n (1 <= n <=) indicating the number of receptacles in the . The next n lines 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 (1 <= m <=) indicating the number of devices your would like T o plug in. Each of the next m lines lists the name of a device followed by the type of plug it uses (which are identical to the type O F receptacle it requires). A device name is a string of in most 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 (1 <= k <=) indicating the number of different varieties of a Dapters that is available. Each of the next K lines describes a variety of adapter, giving the type of receptacle provided by the adapter, followed B Y 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 is plugged in.
Sample Input
Sample Output
1
Source
field=source&key=east+central+north+america+1999 "style=" Text-decoration:none ">East Central North America 1999 Test Instructions: Given some sockets, with electrical appliances, converters. Each socket can only plug one with an electrical appliance or a converter, and each appliance can only plug in a socket or converter, and there are countless converters. The minimum number of electrical appliances can not be used to power up. problem : Difficult in composition, the composition should be aware that the number of nodes may exceed the scope of the topic given. So the array needs to be a little bigger. Just double it. Then the map map needs to avoid repetition or leakage. The virtual source point is connected to each appliance with a capacity of 1. The appliance is connected to a receptacle or converter with a capacity of 1. The converter is connected to the socket. The capacity is INF, and the socket is connected to the virtual meeting point. Capacity is 1.
#include <stdio.h> #include <string.h> #include <string> #include <map> #define MAXN 1010#define MAXM MAXN * MAXN << 1#define maxs 30#define inf 0x3f3f3f3fint N, M, K, source, sink, Num;char Str[maxs], buf[maxs];s Td::map<std::string, int> mp;int HEAD[MAXN], id;struct ndoe {int u, V, C, next;} E[maxm];int DEP[MAXN], PS[MAXN], cur[maxn];void addedge (int u, int v, int c) {e[id].u = u; E[ID].V = v; E[ID].C = C; E[id].next = Head[u];head[u] = id++; e[id].u = v; E[ID].V = u; e[id].c = 0; E[id].next = head[v];head[v] = id++;} void Getmap () {int i; id = 0; num = 3;source = 1; sink = 2;memset (head,-1, sizeof (head)), scanf ("%d", &n); for (i = 0; i < n; ++i) {scanf ("%s", str), if (mp[str] = = 0) Mp[str] = Num++;addedge (Mp[str], sink, 1);} scanf ("%d", &m); for (i = 0; i < m; ++i) {scanf ("%s%s", str, BUF); Mp[str] = num++;if (mp[buf] = = 0) Mp[buf] = Num++;ad Dedge (Mp[str], mp[buf], 1); Addedge (source, Mp[str], 1);} scanf ("%d", &k); for (i = 0; i < K; ++i) {scanf ("%s%s ", str, BUF); if (mp[str] = = 0) Mp[str] = num++;if (mp[buf] = = 0) Mp[buf] = Num++;addedge (Mp[str], mp[buf], INF);}} int dinic (int n, int s, int t) {int TR, res = 0; int I, j, K, F, R, top; while (true) {memset (DEP,-1, n * sizeof (int)); for (f = dep[ps[0] = s] = 0, r = 1; F! = R;) for (i = ps[f++], j = head[i]; J! =-1; j = e[j].next) {if (e[j].c &&-1 = dep[k=e[j].v]) { DEP[K] = Dep[i] + 1; ps[r++] = k; if (k = = T) {f = R; break; }}} if ( -1 = = dep[t]) break; memcpy (cur, head, n * sizeof (int)); for (i = s, top = 0;;) {if (i = = t) {for (k = 0, tr = inf; k < top; ++k) if (e[ps[k]].c < TR) T R = e[ps[f=k]].c; for (k = 0; k < top; ++k) e[ps[k]].c-= TR, e[ps[k]^1].c + = TR; Res + = TR; i = E[ps[top = f]].u; } for (j = cur[i]; cur[i]! = -1;j = Cur[i] = e[cur[i]].next) if (e[j].c && dep[i] + 1 = = dep[e[j].v]) break; if (cur[i]! =-1) {ps[top++] = Cur[i]; i = E[CUR[I]].V; } else {if (0 = = top) break; Dep[i] =-1; i = e[ps[--top]].u; }}} return res;} void Solve () {printf ("%d\n", M-dinic (num, source, sink));} int main () {getmap (); solve (); return 0;}
POJ1087 A Plug for UNIX "Max Stream"