#include <bits/stdc++.h>
using namespace std;
typedef struct
{
int id;
char sex;
int fa, ma;
} P;
const int N = 100100;
P p[N];
void dfs(int s, int idx, set<int> &S)
{
if (idx >= 5)
return;
if (p[s].fa != -1 && p[s].fa != 0)
{
S.insert(p[s].fa);
dfs(p[s].fa, idx + 1, S);
}
if (p[s].ma != -1 && p[s].ma != 0)
{
S.insert(p[s].ma);
dfs(p[s].ma, idx + 1, S);
}
}
int main(void)
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int id;
char sex;
int fa, ma;
scanf("%d %c %d %d", &id, &sex, &fa, &ma);
p[id] = {id, sex, fa, ma};
if (fa != -1)
{
p[fa].id = fa;
p[fa].sex = 'M';
}
if (ma != -1)
{
p[ma].id = ma;
p[ma].sex = 'F';
}
}
int m;
cin >> m;
while (m--)
{
int a, b;
scanf("%d %d", &a, &b);
if (p[a].sex == p[b].sex)
{
printf("Never Mind\n");
continue;
}
set<int> Sa;
set<int> Sb;
dfs(a, 1, Sa);
dfs(b, 1, Sb);
bool flag = true;
for (auto it = Sa.begin(); it != Sa.end(); it++)
{
if (Sb.find(*it) != Sb.end())
{
flag = false;
break;
}
}
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}
L2-016 愿天下有情人都是失散多年的兄妹 (25分)团体设计天梯赛
最新推荐文章于 2022-04-22 15:32:27 发布