当前位置:网站首页>L2-030 冰岛人 (25 分) (最近公共祖先 思维
L2-030 冰岛人 (25 分) (最近公共祖先 思维
2022-04-22 09:17:00 【lcxdz】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
unordered_map<string, int> sex;
unordered_map<string, int> id;
unordered_map<int, string> name;
struct node {
string s;
};
unordered_map<string,node>arr;
int tot = 1, flag;
bool check(string a,string b)
{
// cout << name[u] << "\n";
int tota=0;
while(a!=""){
tota++;
int totb=0;
string p=b;
while(p!=""){
totb++;
if(a==p&&(tota<=4||totb<=4)){
return 0;
}
if(tota>4&&totb>4)return 1;
p=arr[p].s;
}
a=arr[a].s;
}
return 1;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
string a, b, A, B;
cin >> a >> b;
if (id[a] == 0)
{
id[a] = tot;
name[tot++] = a;
}
if (b.back() == 'm')
{
B = b.substr(0, b.size() - 1), sex[a] = 1;
}
else if (b.back() == 'f')
sex[a] = 2, B = b.substr(0, b.size() - 1);
else if (b.back() == 'n')
{
sex[a] = 1;
B = b.substr(0, b.size() - 4);
if (id[B] == 0)
{
id[B] = tot;
name[tot++] = B;
}
arr[a]={
B};
// cout<<a<<" "<<id[a]<<" "<<id[B]<<"\n";
// v[id[a]].push_back(id[B]);
}
else if (b.back() == 'r')
{
sex[a] = 2;
B = b.substr(0, b.size() - 7);
if (id[B] == 0)
{
id[B] = tot;
name[tot++] = B;
}
arr[a]={
B};
// cout<<a<<" "<<id[a]<<" "<<id[B]<<"\n";
// v[id[a]].push_back(id[B]);
}
// v[id[a]].push_back(id[B]);
}
int q;
cin >> q;
while (q--)
{
string a1, b1, a2, b2;
cin >> a1 >> b1 >> a2 >> b2;
if (id[a1] == 0 || id[a2] == 0)
{
cout << "NA\n";
continue;
}
if (sex[a1] == sex[a2])
{
cout << "Whatever\n";
continue;
}
flag = 0;
flag=check(a1, a2);
if (!flag)
{
cout << "No\n";
}
else
cout << "Yes\n";
}
return 0;
}
版权声明
本文为[lcxdz]所创,转载请带上原文链接,感谢
https://minelois.blog.csdn.net/article/details/124331755
边栏推荐
- openlayer中,svg图片无width如何修改大小
- 问题解决:dpkg-deb: error: package name has characters that aren‘t lowercase alphanums or ‘-+.‘
- 手动搭建hyperledger fabric v2.x 生产网络(四)创建通道,链码的生命周期
- I/O知识点总结
- 基于麒麟SP10服务器版的Kubernetes集群安装
- Merge two ordered linked lists (iteration)
- PHP & Laravel & 掌握 api 生成 token 的几种方式以及一些注意事项(坑)
- vector常见接口的用法
- 2022年危险化学品经营单位安全管理人员上岗证题库及在线模拟考试
- Stream API optimization code
猜你喜欢

新书推荐——IPv6技术与应用(锐捷版)

网站域名申请问题

(cvpr-2014) deep learning face representation by predicting 10000 categories

1958年高考数学真题

Kernel pwn 基础教程之 Heap Overflow

MySQL on duplicate key update / case when syntax

MySQL uses the source command to import SQL. There is an error. I think it should be a coding problem. I don't know how to solve it

从科普、医生培训及创新医械产品推广需求出发,「佰医绘」如何布局医学可视化SaaS服务?

在销量压力下,国产手机开始降价了,但还没有放下最后的面子

2022 high voltage electrician test simulation 100 questions and answers
随机推荐
web 学习记录(中)
Online CSV to yaml tool
引水入城 洛谷P1514
智能手表的突破和新发展机遇
玩转Kubernetes—基础概念篇
建议:块引用排序按照关键词的顺序排序
MySQL uses the source command to import SQL. There is an error. I think it should be a coding problem. I don't know how to solve it
从辩证法角度,如何认知产品
微信公众平台测试号申请、使用HBuilder X与微信开发者工具实现授权登陆功能以及单点登录
【图像隐写】Fixed Neural Network Steganography: Train the images, not the network 整理
oracle18c rac安装grid执行脚本root.sh报错,PRCR-1013 : 无法启动资源 ora.ons
ShardingSphere简介与分表使用
分布式场景业务操作日志实现(基于redis轻量)
ERP 集成对公司系统完善的重要性
The bare metal machine developed by single chip microcomputer can also "multitask"?
Does pytorch model load the running test set and the running test set in the training process have inconsistent results?
numpy笔记(vstack,random.permutation,empty_like,empty,diff,random.choice,random.randint,isin)
网站域名申请问题
Neo4j: merge [create if it doesn't exist, modifiable if it already exists]
手動搭建hyperledger fabric v2.x 生產網絡(四)創建通道,鏈碼的生命周期