A Plug for UNIX
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 15597   Accepted: 5308

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 receptacles 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 many years ago when reporters used very few electric and electronic devices and is equipped 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 is likely to be long and tedious, you want to be able to plug in as many as you can. 
Before the meeting begins, you gather up all the devices that the reporters would like to use, and attempt to set them up. You notice that some of the devices use plugs for which there is no receptacle. You wonder if these devices are from countries that didn't exist when the room was built. For some receptacles, there are several devices that use the corresponding plug. For other receptacles, 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 essentially 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 receptacles in the room. The next n lines list the receptacle types found in the room. Each receptacle 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 would 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 receptacle 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 receptacle 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
X A
X D

Sample Output

1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int big=50000;
int max(int a,int b) {return a>b?a:b;};
int min(int a,int b) {return a<b?a:b;};
struct edge{
int to,cap,rev;
}; vector<edge> G[2500];
map<string,int> mp;
int n,m,k,level[2500],iter[2500];
char s[50],a[50],b[50];
void add_edge(int u,int v,int cap)
{
G[u].push_back(edge{v,cap,G[v].size()});
G[v].push_back(edge{u,0,G[u].size()-1});
} void bfs(int s)
{
queue<int> q;
q.push(s);
level[s]=1;
while(q.size())
{
int now=q.front();q.pop();
for(int i=0;i<G[now].size();i++)
if(G[now][i].cap>0)
{
edge e=G[now][i];
if(level[e.to]<0)
{
level[e.to]=level[now]+1;
q.push(e.to);
}
}
}
}
int dfs(int s,int t,int minn)
{
if(s==t)
return minn;
for(int &i=iter[s];i<G[s].size();i++)
{
edge &e=G[s][i];
if(level[e.to]>level[s]&&e.cap>0)
{
int k=dfs(e.to,t,min(minn,e.cap));
if(k>0)
{
e.cap-=k;
G[e.to][e.rev].cap+=k;
return k;
}
}
}
return 0;
} int max_flow(int s,int t)
{
int ans=0,temp;
for(;;)
{
memset(level,-1,sizeof(level));
bfs(s);
if(level[t]<0)
return ans;
memset(iter,0,sizeof(iter));
while((temp=dfs(s,t,inf))>0)
ans+=temp;
}
return ans;
} void init()
{
mp.clear();
for(int i=1;i<=2000;i++) G[i].clear();
} void build()
{
int num=0;
for(int i=1;i<=n;i++)
{
int u;
scanf("%s",s);
mp[s]=++num;
add_edge(0,mp[s],1);
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%s %s",a,b);
mp[a]=++num;
if(!mp[b]) mp[b]=++num;
add_edge(mp[b],mp[a],1);
add_edge(mp[a],2000,1);
}
scanf("%d",&k);
for(int i=1;i<=k;i++)
{
scanf("%s %s",a,b);
if(!mp[a]) mp[a]=++num;
if(!mp[b]) mp[b]=++num;
add_edge(mp[b],mp[a],inf);
}
} void solve()
{
printf("%d\n",m-max_flow(0,2000));
} int main()
{
while(~scanf("%d",&n))
{
init();
build();
solve();
}
return 0;
}

  分析:出的很渣的一道题,明明是道最大流裸题,结果题目讲的半天都含糊不清有歧义,,

最大流裸题,,唯一有收获的是map的使用map<string,int> mp保存字符串非常方便,直接scanf("%s",s)   然后mp[s]就可以读出mp中与s相同的字符串的个数

然后mp[]

最新文章

  1. JAVA NIO Channel
  2. 用.NET MVC实现长轮询,与jQuery.AJAX即时双向通信
  3. R语言爬虫初尝试-基于RVEST包学习
  4. 使用ab压测网页结果分析
  5. CSS权威指南 - 基本视觉格式化 4
  6. ubuntu安装 laravel 过程中出现: mcrypt php extension required 的问题 | 以及composer相关问题 | Nginx安装
  7. windbg sos版本不匹配问题解决
  8. [BS-04] 在iOS中对系统定义的类的readonly属性可通过KVC进行赋值
  9. BZOJ 3226: [Sdoi2008]校门外的区间
  10. MVC用户登陆验证及权限检查(Form认证)
  11. GIT 分支的理解
  12. WebApi 4.0 默认方式不支持HttpGet 请求
  13. CentOS7--Xshell网络中断引起的vi编辑文件问题
  14. SQL数据库注入防范 ASP.NET Globle警告
  15. CSS自定义动画
  16. AR增强现实开发介绍
  17. css基本语法及页面引用
  18. Javascript杂!
  19. Python Web简单加法器的实现--Python
  20. Oracle 常用sql整理

热门文章

  1. 设计模式:备忘录模式(Memento)
  2. 【转】在C#中使用Json.Net进行序列化和反序列化及定制化
  3. mybatis 基础(二) 动态sql 关于where if / where choose when otherwise
  4. Luogu P4436 [HNOI/AHOI2018]游戏
  5. thinkphp5.1 关于加载静态资源路径问题
  6. 从入门到自闭之Python随机模块
  7. 使用Python的文本挖掘的特征选择/提取
  8. Eclipce远程调试
  9. markdown图片转换demo
  10. O011、理解 virbr0