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. 一句powershell调用mimikatz抓密码

    mimikatz神器大家都知道吧,可以抓取系统内的明文密码,但是平时我们测试的时候需要把mimikatz的几个文件上传到目标系统上面,然后再手工执行几个命令才能搞定,今天无意访问一个大神的博客,发现其 ...

  2. bzoj 1791: [Ioi2008]Island 岛屿【基环树+单调队列优化dp】

    我太菜了居然调了一上午-- 这个题就是要求基环树森林的基环树直径和 大概步骤就是找环->dp找每个环点最远能到达距离作为点权->复制一倍环,单调队列dp 找环是可以拓扑的,但是利用性质有更 ...

  3. golang——database/sql包学习

    1.database/sql包 sql包提供了保证SQL或类SQL数据库的泛用接口. 使用sql包时必须注入(至少)一个数据库驱动. (1)获取mysql driver:go get -v githu ...

  4. ORACLE批量绑定FORALL与BULK COLLECT

    FORALL与BULK COLLECT的使用方法: 1.使用FORALL比FOR效率高,因为前者只切换一次上下文,而后者将是在循环次数一样多个上下文间切换. 2.使用BLUK COLLECT一次取出一 ...

  5. 查询编辑器便捷特性【MSSQL】

    SQL Server团队为用户提供了一个便捷的特性 如果没有突出显示文本,那么按F5,执行整个批处理. 如果突出显示文本(选中SQL命令),那么只执行选中文本.

  6. P3373 【模板】线段树 2 区间求和 区间乘 区间加

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.将某区间每一个数乘上x 3.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含三个整数N.M.P,分别 ...

  7. JavaScript设计模式 (1) 原型模式

    原型模式(Prototype):用原型实例指向创建类对象,使用于创建新对象的类共享原型对象的属性以及方法. //图片轮播类 var LoopImages = function (imgArr, con ...

  8. Linux 配置 nginx + php

    为什么!!!我配过的服务器已经有5.6个了吧,为什么每一次配置都能要了我的老命??这次写清楚过程,以后再要被配服务器坑,我特么要砍人了. 提示:测试网站能否访问的时候,最好关掉浏览器的缓存功能或者勤清 ...

  9. dubbo-monitor安装及配置过程

    安装 1. 使用git下载(git clone https://github.com/alibaba/dubbo.git)或者从http://dubbo.io/下载源码 2. cd到dubbo的根目录 ...

  10. vue-element-admin使用常见问题

    一.vue-element-admin添加快捷导航 这个组件是基于vue-i18n因此,首先在项目中安装i18n npm install --save vue-i18n 然后main.js中引入 im ...