A Plug for UNIX

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 1087
64-bit integer IO format: %lld      Java class name: Main

 
 
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

Source

 
解题:建图什么的完全不懂。。。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
map<string,int>mp;
queue<int>q;
int n,m,k,c[maxn][maxn] = {},S,T,p[maxn],maxFlow = ;
void bfs() {
while(true) {
memset(p,-,sizeof(p));
while(!q.empty()) q.pop();
q.push(S);
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = ; i <= T; i++) {
if(p[i] == - && c[u][i] != ) {
p[i] = u;
q.push(i);
}
}
if(p[T] != -) break;
}
if(p[T] == -) break;
for(int u = T; u != S; u = p[u]) {
c[p[u]][u] -= ;
c[u][p[u]] += ;
}
maxFlow += ;
}
}
int main() {
string plug,plug2,device;
int i,t;
cin>>n;
for(i = ; i <= n; i++) {
cin>>plug;
mp[plug] = i;
}
t = n;
cin>>m;
for(i = ; i <= m; i++) {
cin>>device>>plug;
if(mp.find(plug) == mp.end()) mp[plug] = ++t;
c[i][m+mp[plug]] = ;
}
cin>>k;
for(i = ; i <= k; i++) {
cin>>plug>>plug2;
if(mp.find(plug) == mp.end()) mp[plug] = ++t;
if(mp.find(plug2) == mp.end()) mp[plug2] = ++t;
c[m+mp[plug]][m+mp[plug2]] = INF;
}
S = ;
T = m+t+;
for(int i = ; i <= m; i++) c[S][i] = ;
for(int i = ; i <= n; i++) c[m+i][T] = ;
bfs();
printf("%d\n",m-maxFlow);
return ;
}

BNUOJ 1206 A Plug for UNIX的更多相关文章

  1. UVA 753 A Plug for UNIX(二分图匹配)

    A Plug for UNIX You are in charge of setting up the press room for the inaugural meeting of the Unit ...

  2. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

  3. POJ1087 A Plug for UNIX(网络流)

                                       A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  4. poj 1087 C - A Plug for UNIX 网络流最大流

    C - A Plug for UNIXTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contes ...

  5. 【poj1087/uva753】A Plug for UNIX(最大流)

    A Plug for UNIX   Description You are in charge of setting up the press room for the inaugural meeti ...

  6. UVA 753 - A Plug for UNIX(网络流)

      A Plug for UNIX  You are in charge of setting up the press room for the inaugural meeting of the U ...

  7. POJ1087 A Plug for UNIX 【最大流】

    A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13855   Accepted: 4635 ...

  8. UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)

    解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...

  9. POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)

    POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...

随机推荐

  1. E20171226-hm

    stack n.栈 heap  n.堆 backtracking 回溯法,後戻り storage  n. 贮存; 贮藏; 储藏处,仓库; 贮存器,蓄电(瓶); ストレージ

  2. 【洛谷2617_BZOJ1901】Dynamic Rankings(树套树)

    题目: 洛谷 2617 BZOJ 1901 是权限题,\(n=10^4\) ,内存 128 MB :洛谷 2617 \(n=10^5\) ,内存 1024 MB ,数据比较坑. 分析: 蒟蒻初学树套树 ...

  3. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  4. ACM_输出格式

    输出格式 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某水比参加了XX杯,但是他太水,所以三等都木有,所以他决定出一道水题水一 ...

  5. Android 性能优化(21)*性能工具之「GPU呈现模式分析」Profiling GPU Rendering Walkthrough:分析View显示是否超标

    Profiling GPU Rendering Walkthrough 1.In this document Prerequisites Profile GPU Rendering $adb shel ...

  6. 240 Search a 2D Matrix II 搜索二维矩阵 II

    编写一个高效的算法来搜索 m x n 矩阵中的一个目标值.该矩阵具有以下特性:    每行的元素从左到右升序排列.    每列的元素从上到下升序排列.例如,考虑下面的矩阵:[  [1,   4,  7 ...

  7. MongoDB学习笔记~复杂条件拼接和正则的使用

    在大叔lind框架里有日志组件logger,而在日志实现方式上有file,mongodb,sql,json等方式,对分布式日志处理上大叔推荐使用mongodb进行存储,除了它的高效写入,灵活的结构外, ...

  8. iOS popViewControllerAnimated后刷新原先的表格

    当主页面列表push子页面,子页面修改后pop回主页面后应该刷新主页面列表数据,不修改子页面信息就不刷新主页面列表,这里介绍个取巧的方法:利用[NSNotificationCenter default ...

  9. Angular JS中自定义标签 属性绑定的解释

    看到自定义标签的文档时,文档作者解释的能力实在太弱,也可能是本人太笨,一下绕不过来. 看了一个stackoverflow答案,才算明白,在此贴出翻译,以供大家参考. .csharpcode, .csh ...

  10. 第八届蓝桥杯省赛C/C++ A组第4题 方格分割

    参考了http://blog.csdn.net/y1196645376/article/details/69718192,这个大哥的思路很巧妙. 思路: dfs. 实现: #include <i ...