QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#397. 环球旅行者大会

Statistics

环球旅行者协会正在组织一场盛大的环球旅行者大会。这并非易事,因为旅行者们一直在移动。协会共有 $k$ 名成员。他们在全球范围内移动,对他们而言,全球由 $n$ 个避难所和连接避难所的单向路径组成。每位旅行者的旅行方式如下:每天清晨,一位在前一天晚上住在某个避难所的旅行者,会选择一条从该避难所出发的路径,并在当天沿着该路径(按规定方向)行进,在黄昏前到达下一个避难所,并在那里度过当晚。我们注意到,每个避难所都有路径通向其他避难所,因此没有旅行者会陷入困境。

已知每位旅行者在初始夜晚所在的位置,请确定这 $k$ 位旅行者是否能在某个傍晚在同一个避难所集合,如果可以,请计算他们集合所需的最少天数。

输入格式

第一行包含三个整数 $n, m, k$ ($2 \le n \le 250, n \le m \le n^2, 2 \le k \le n$),分别表示避难所的数量、路径的数量以及旅行者的数量,整数间以空格分隔。避难所编号为 $1$ 到 $n$。

第二行包含一个由 $k$ 个整数 $s_1, s_2, \dots, s_k$ ($1 \le s_i \le n$) 组成的序列,整数间以空格分隔,其中 $s_i$ 表示第 $i$ 位旅行者在初始夜晚所在的避难所编号。

接下来的 $m$ 行描述了路径。第 $j$ 条路径由一对整数 $a_j, b_j$ ($1 \le a_j, b_j \le n$) 表示(不一定不同),整数间以空格分隔,表示该路径从避难所 $a_j$ 通向避难所 $b_j$。输入中不会重复出现相同的路径。对于每个避难所,至少有一条路径从它出发。

输出格式

如果旅行者无法集合,输出一行 NIE(波兰语中的“不”)。否则,第一行输出 TAK(波兰语中的“是”),第二行输出一个整数:旅行者在同一个避难所集合所需的最少天数。

样例

样例输入 1

5 7 3
1 2 3
1 2
1 3
2 3
3 4
4 1
4 5
5 1

样例输出 1

TAK
3

说明 1

下图展示了避难所和路径。旅行者初始夜晚所在的避难所颜色较深。为了集合,旅行者可以遵循以下路线: $1 \to 3 \to 4 \to 1$,$2 \to 3 \to 4 \to 1$,$3 \to 4 \to 5 \to 1$。

样例输入 2

5 5 3
1 2 3
1 2
2 3
3 4
4 5
5 1

样例输出 2

NIE

子任务

测试集由以下子任务组成。每个子任务内可能包含多个测试点。 如果程序仅输出了正确的第一行,将获得该测试点 40% 的分数。请注意,程序仍需正常终止,且不能超过时间和内存限制。

子任务 条件 分数
1 $n \le 10$ 20
2 可以在任何避难所停留,$n > 10$ 30
3 其余情况 50

严格来说,第二个子任务中的每个测试点都具有以下性质:对于每个避难所,都存在一条从该避难所通向其自身的路径,即自环。

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.