QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#8656. Is-A? Has-A? Who Knowz-A?

الإحصائيات

面向对象编程中两个熟悉的概念是 is-a(是一个)和 has-a(有一个)关系。给定两个类 A 和 B,如果 A 是 B 的子类,我们称 A is-a B;如果 A 的某个字段类型为 B,我们称 A has-a B。例如,我们可以想象一种面向对象语言(称为 ICPC++),其代码如图 E.1 所示,其中类 Day is-a Time,类 Appointment 既是 Datebook 又是 Reminder,且类 Appointment has-a Day

图 E.1:两个 ICPC++ 类。

class Day extends Time
{
    ...
}
class Appointment extends Datebook, Reminder
{
    private Day date;
    ...
}

这两种关系具有传递性。例如,如果 A is-a B 且 B is-a C,则 A is-a C。如果将上一句中所有的 is-a 替换为 has-a,该结论同样成立。它也适用于 is-a 和 has-a 的组合:在上面的例子中,Appointment has-a Time,因为它 has-a DayDay is-a Time。类似地,如果类 Datebook has-a Year,则 Appointment has-a Year,因为 Appointment is-a Datebook

在本题中,你将获得一组 is-a 和 has-a 关系,以及一组形式为 A is/has-a B 的查询。你必须确定每个查询是真还是假。

输入格式

输入以两个整数 $n$ 和 $m$ 开始($1 \le n, m \le 10\,000$),其中 $n$ 指定了给定的 is-a 和 has-a 关系的数量,$m$ 指定了查询的数量。接下来的 $n$ 行,每行包含一个给定的关系,格式为 $c_1 \ r \ c_2$,其中 $c_1$ 和 $c_2$ 是单词类名,$r$ 是字符串 “is-a” 或 “has-a”。随后是 $m$ 行查询,每行使用相同的格式。在 $n+m$ 行中最多有 500 个不同的类名,且最后 $m$ 行中的所有类名在最初的 $n$ 行中至少出现过一次。给定类之间的所有 is-a 和 has-a 关系都可以从给定的 $n$ 个关系中推导出来。Is-a 关系不能是循环的(除了平凡的恒等关系 “x is-a x”)。

输出格式

对于每个查询,显示查询编号(从 1 开始)以及该查询是真还是假。

样例

输入格式 1

5 5
Day is-a Time
Appointment is-a Datebook
Appointment is-a Reminder
Appointment has-a Day
Datebook has-a Year
Day is-a Time
Time is-a Day
Appointment has-a Time
Appointment has-a Year
Day is-a Day

输出格式 1

Query 1: true
Query 2: false
Query 3: true
Query 4: true
Query 5: true

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.