QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#16783. 游客

Estadísticas

Lemuria 的道路系统相当复杂。有些城市由单向或双向道路连接。然而,狐猴们将他们的道路保持得井井有条,并且他们的路线图总是最新的。

游客 G. 刚刚乘坐企鹅航空(Penguin Air)的航班抵达 Lemuria 的城市 $S$。他的回程航班将从城市 $F$ 出发。G. 有一份 Lemuria 最受欢迎的景点列表,他渴望游览所有这些景点。此外,他拥有最新版本的路线图,因此对于每个城市 $P$,他都有一份可以从 $P$ 直接到达的城市列表。你的任务是帮助这位游客规划一条穿越 Lemuria 的路线,该路线从 $S$ 开始,经过所有有景点的城市(顺序任意),并结束于 $F$。

输入格式

输入的第一行包含四个整数:Lemuria 的城市总数 $N$($1 \le N \le 2000$)、有景点的城市数量 $K$($0 \le K \le N$),以及起点城市 $S$ 和终点城市 $F$ 的编号(所有城市从 $1$ 开始编号)。

第二行包含 $K$ 个互不相同的数字——有景点的城市编号。

接下来的 $N$ 行包含路线图。这些行中的每一行都包含 $N$ 个字符:如果输入的第 $(p + 2)$ 行的第 $q$ 个字符是 1,则表示存在一条从城市 $p$ 到城市 $q$ 的直接道路;如果是 0,则表示没有直接道路。不存在从一个城市到其自身的道路。

输出格式

如果不存在满足条件的路线,输出应包含一行,写有单词 NO

否则,输出的第一行应包含单词 YES,第二行应包含路线中的城市数量 $M$($M \le N^2$),接下来的行中应包含 $M$ 个数字——路线中的城市编号。路线中的第一个城市应为 $S$,最后一个城市应为 $F$,且路线中任意两个相邻城市之间必须存在一条从前者到后者的直接道路。

样例

输入样例 1

4 4 1 2
1 2 3 4
0100
0011
1000
1000

输出样例 1

YES
8
1 2 4 1 2 3 1 2

输入样例 2

4 2 1 4
2 3
0110
0001
0001
0000

输出样例 2

NO

输入样例 3

4 1 2 3
4
0010
1001
1000
0100

输出样例 3

YES
7
2 4 2 1 3 1 3

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.