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 ...
随机推荐
- DELPHI XE5 UP2 运行IOS 遇到 Wrapper init failed: (null)问题的解决办法
一.问题表现: 在MAC OSX(10.9.2)上安装了比较新的XCODE5.1 和COMMAND LINE TOOLS 在DELPHI XE5 UP2上放了一个按钮,输出到MAC OSX上,出现: ...
- 20145218PC平台逆向破解
20145218PC平台逆向破解 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. 该程序同 ...
- 微信Token验证
/// <summary> /// 微信验证 /// </summary> /// <param name="echostr"></par ...
- WebJars——web端静态资源的jar包
1.WebJars介绍 Web前端使用了越来越多的JS或CSS,如jQuery,Backbone.js和Bootstrap.一般情况下,我们是将这些Web资源拷贝到Java Web项目的webapp相 ...
- git you need to resolve your current index first 解决办法
当使用git checkout 切换分支时会提示you need to resolve your current index first,使用如下命令即可解决. $ git reset --merge
- JSON Assertion(JSON断言)
JSON断言允许你完成对JSON文档的校验,首先,如果如果数据不是JSON,则会解析失败:其次,JMeter会用指定语法寻找指定的path,如果没有找到,则会失败:第三,如果验证期望值为null,JM ...
- fiddler 代理调试本地手机页面
https://www.cnblogs.com/zichi/p/4944581.html
- 【bzoj4836】二元运算 分治FFT
Description 定义二元运算 opt 满足 现在给定一个长为 n 的数列 a 和一个长为 m 的数列 b ,接下来有 q 次询问.每次询问给定一个数字 c 你需要求出有多少对 (i, j) 使 ...
- Python3之uuid模块
一. 简介 UUID是128位的全局唯一标识符,通常由32字节的字母串表示.它可以保证时间和空间的唯一性,也称为GUID. 全称为:UUID--Universally Unique IDentifie ...
- js 三大家族之offset
JS中的offset家族: 一.offsetWidth与offsetHeight: 获取的是元素的实际宽高 = width + border + padding 注意点: 1.可以获取行内及内嵌的宽高 ...