QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#14567. 快乐的挂钩

统计

终于成了!你匹配成功了!兴奋之余,你和你的配对对象 Hannah 决定一起去晨练散步。由于你们俩住在不同的城市,你们决定在某个火车站碰头。

前往各自城市的火车站没有问题。然而,国家铁路网正在进行的翻新工程严重影响了可用的线路连接。其中一些线路完全无法使用,另一些则变成了单向通行。这使得你们是否能够碰头变得不确定。

图 H.1:第三个样例的直观展示。Hannah 从车站 4 出发,你从车站 1 出发。你们都可以到达车站 3 进行碰头。

你在网上找到了可用火车线路的列表。如果一个火车站是你和 Hannah 都能到达的,那么它就是适合碰头的车站。请判断是否存在这样一个适合碰头的火车站,还是必须将晨练散步推迟到另一天。

输入格式

输入包含以下内容:

  • 第一行包含两个整数 $n$ 和 $m$($2 \le n \le 10^5$,$0 \le m \le 10^5$),分别表示火车站的数量和火车线路的数量。
  • 接下来的 $m$ 行,每行包含两个整数 $x$ 和 $y$($1 \le x, y \le n$ 且 $x \ne y$),表示从火车站 $x$ 到火车站 $y$ 的一条单向直接火车线路。
  • 最后一行包含两个整数 $a$ 和 $b$($1 \le a, b \le n$ 且 $a \ne b$),分别表示你和 Hannah 出发的火车站。

保证没有火车线路会被重复列出。

输出格式

如果不存在适合碰头的火车站,输出 "no"。

否则,输出 "yes",后跟该火车站的编号。如果有多个可行的解,你可以输出其中任意一个。

样例

输入样例 1

3 2
1 3
2 3
1 2

输出样例 1

yes
3

输入样例 2

3 2
2 1
2 3
1 3

输出样例 2

no

输入样例 3

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

输出样例 3

yes
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.