当前位置:网站首页>L2-030 Icelander (25 points) (nearest public ancestor)
L2-030 Icelander (25 points) (nearest public ancestor)
2022-04-22 09:30: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://yzsam.com/2022/04/202204220916336659.html
边栏推荐
猜你喜欢

在线CSV转YAML工具

深度解析MOS管的GS波形分析-KIA MOS管

esp-01s在arduino中的开发(一)

经典场效应管如何快速关断技巧-KIA MOS管

LeetCode 447. 回旋镖的数量 (排列组合问题)

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

编写一个简单的考试程序,在控制台完成出题、答题的交互。试题(Question)分为单选(SingleChoice)和多选( MultiChoice)两种。

Detailed explanation of Navicat 15 installation and related problems

ShardingSphere简介与分表使用

微搭低代码零基础入门课
随机推荐
etcd 如何实现同步监听
Open source, not just coding
找出二维数组最大的一个数
一文MOS管串联并联驱动应用解析-KIA MOS管
云数引领下,桑达股份2021年营收427.04亿元,同比增长33.21%
网络抖动工具clumsy
log4j2配置
unity之动态批处理和静态批处理
多线程技术核心
Computer dust removal and mechanical hard disk installation records
手動搭建hyperledger fabric v2.x 生產網絡(四)創建通道,鏈碼的生命周期
Online yaml to properties tool
P8资料大放送
MOS管及MOS管驱动电路案例分析-KIA MOS管
L3-003 社交集群 (30 分) (并查集
杰理之CPU性能测试【篇】
LeetCode39-组合总和
Led by the cloud number, the revenue of Sanda shares in 2021 was 42.704 billion yuan, a year-on-year increase of 33.21%
服务端Watch监听处理过程解析
理解MySQL的MVCC同一个事务第一次快照读和第二次快照读——笔记