TOJ 4289 Unrequited Love
Description
There are n single boys and m single girls. Each of them may love none, one or several of other people unrequitedly and one-sidedly. For the coming q days, each night some of them will come together to hold a single party. In the party, if someone loves all the others, but is not loved by anyone, then he/she is called king/queen of unrequited love.
Input
There are multiple test cases. The first line of the input is an integer T ≈ 50 indicating the number of test cases.
Each test case starts with three positive integers no more than 30000 -- n m q. Then each of the next n lines describes a boy, and each of the next m lines describes a girl. Each line consists of the name, the number of unrequitedly loved people, and the list of these people's names. Each of the last q lines describes a single party. It consists of the number of people who attend this party and their names. All people have different names whose lengths are no more than 20. But there are no restrictions that all of them are heterosexuals.
Output
For each query, print the number of kings/queens of unrequited love, followed by their names in lexicographical order, separated by a space. Print an empty line after each test case. See sample for more details.
Sample Input
2
2 1 4
BoyA 1 GirlC
BoyB 1 GirlC
GirlC 1 BoyA
2 BoyA BoyB
2 BoyA GirlC
2 BoyB GirlC
3 BoyA BoyB GirlC
2 2 2
H 2 O S
He 0
O 1 H
S 1 H
3 H O S
4 H He O S
Sample Output
0
0
1 BoyB
0 0
0
Source
不会写,看似水题的东西没想到这么难。
假如一个人存在unrequited love,那么表示这个结点没有入度,且这个点到所有的点一定是有路径的。
来自大牛的解题思路,数据比较的大用vector数组来建图,并且要使用二分找来判断是否存在通路。
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#define MAXN 60005
using namespace std; vector< int > V[MAXN];
vector< int > VP;
map< string , int > M;
string Name[MAXN];
int cnt; void initVP(){
VP.clear();
} void initGraph(){
for(int i=; i<MAXN; i++){
V[i].clear();
}
} void addString(string s){
if(M.find(s)==M.end()){
M[s]=cnt;
Name[cnt++]=s;
}
} void createMap(int n){
char ch[];
string s;
int c,u,v;
for(int i=; i<n; i++){
scanf("%s" ,ch);
s=string(ch);
addString(s);
u=M[s];
scanf("%d" ,&c);
for(int j=; j<c; j++){
scanf("%s" ,ch);
s=string(ch);
addString(s);
v=M[s];
V[u].push_back(v);
}
sort(V[u].begin(),V[u].end());
}
} int main()
{
int c,t;
int n,m,q;
scanf("%d" ,&t);
while( t-- ){
M.clear();
cnt=;
initGraph();
scanf("%d %d %d" ,&n ,&m ,&q);
createMap(n);
createMap(m);
while( q-- ){
initVP();
char ch[];
string s;
scanf("%d" ,&c);
while( c-- ){
scanf("%s" ,ch);
s=string(ch);
VP.push_back(M[s]);
}
int size=VP.size();
int i,j;
for(i=; i<size; i++){
for(j=; j<size; j++){
if(i==j)continue;
if( !binary_search( V[VP[i]].begin() , V[VP[i]].end(), VP[j])
|| binary_search( V[VP[j]].begin(), V[VP[j]].end(), VP[i]))
break;
}
if(j==size){
printf("1 %s\n",Name[VP[i]].c_str());
break;
}
}
if(i==size){
puts("");
}
}
puts("");
}
return ;
}
TOJ 4289 Unrequited Love的更多相关文章
- HDU 4289:Control(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- zjuoj 3601 Unrequited Love
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3601 Unrequited Love Time Limit: 16 Sec ...
- hdu 4289 最大流拆点
大致题意: 给出一个又n个点,m条边组成的无向图.给出两个点s,t.对于图中的每个点,去掉这个点都需要一定的花费.求至少多少花费才能使得s和t之间不连通. 大致思路: 最基础的拆点最大 ...
- ZOJ 3601 Unrequited Love 浙江省第九届省赛
Unrequited Love Time Limit: 16 Seconds Memory Limit: 131072 KB There are n single boys and m si ...
- hdu 4289 Control(最小割 + 拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 Control Time Limit: 2000/1000 MS (Java/Others) Mem ...
- TOJ 1702.A Knight's Journey
2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http:// ...
- TOJ 1139.Compromise
2015-06-03 问题简述: 大概就是输入两段文本(用小写英文字母表示),分别用#表示一段话的结束输入,输出这两个文本的最长公共子序列. 简单的LCS问题,但是输入的是一段话了,而且公共部分比较是 ...
- 优先队列运用 TOJ 4123 Job Scheduling
链接:http://acm.tju.edu.cn/toj/showp4123.html 4123. Job Scheduling Time Limit: 1.0 Seconds Memory ...
随机推荐
- 转 XlsReadWriteII 的博文(自留参考)
如何使用XlsReadWriteII在Delphi中读取Excel文件 XLSReadWriteII v5.20.01a for Delphi XE5 x32下载地址: http://download ...
- java代码实现顺序队列
java实现顺序队列 package xianxinTable; import java.util.ArrayList; import java.util.Iterator; import com.s ...
- struts2中错误提示:There is no Action mapped for namespace / and action name
当在struts2中运行时出现如上所述错误时: 1.在src目录下创建struts.xml一定要注意拼写 2.struts.xml文件中引入和extend是否正确 3.在web.xml 中<we ...
- 微软日志工厂 Microsoft.Extensions.Logging 中增加 log4net 的日志输出
前提: 需要nuget Microsoft.Extensions.Logging.Log4Net.AspNetCore 2.2.6: 描述:解决 .net core 微软日志工厂 Micros ...
- 搭建基于MinGW平台的《OpenGL蓝皮书(OpenGL SuperBibe 5th)》示例代码编译环境
副标题:搭建基于MinGW平台的<OpenGL超级宝典>(OpenGL蓝皮书第5版)GLTools 编译环境.示例代码:Triangle.cpp @ SB5.zip 以下内容以及方法均参考 ...
- 自定义类型转换器 及 使用 ServletAPI 对象作为方法参数
自定义类型转换器使用场景: jsp 代码: <!-- 特殊情况之:类型转换问题 --> <a href="account/deleteAccount?date=2018- ...
- ASP Session 对象
http://www.w3school.com.cn/asp/asp_sessions.asp
- ListBox Dock Fill 总是有空隙的问题
ListBox Dock设置了Fill, Right等 设计界面如己所愿,但是实际运行时,底部总是有不小的空隙. 原因是ListBox有一个属性: IntergralHeight 默认为True 此属 ...
- uoj #297. 【CTSC2017】密钥
#297. [CTSC2017]密钥 一个密钥是一个长度为 n=2k+1n=2k+1 的字符串,它包含 11 个字母X.kk 个字母 A 和 kk 个字母 B.例如 k=3k=3 时,BAXABAB ...
- centos7 docker 安装 mysql5.7.24 导入12G的sql
先在CentOS7里面安装docker Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker .通过 uname - ...