QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#7140. Popo 排序

Statistics

Popo 是 bobo 的一位傻朋友,他正在学习猴子排序(bogo sort)。他立刻发明了自己的版本,如下面的代码所示:

function sort(s)
success := False
for i := 1, 2, ..., m do
if s[a[i]] > s[b[i]] then
swap s[a[i]] and s[b[i]]
success := True
end
end
if success then
return sort(s)
else
return s
end
end

请判断 Popo 的版本是否正确(即能否将所有长度为 $n$ 的序列排序为非递减顺序)。

输入格式

第一行包含两个整数 $n, m$ ($1 \le n \le 1000000, 0 \le m \le 1000000$)。 接下来 $m$ 行,每行包含两个整数 $a_i, b_i$ ($1 \le a_i, b_i \le n$)。

输出格式

如果该版本正确,输出 “Yes”,否则输出 “No”。

样例

样例输入 1

3 2
1 2
2 3

样例输出 1

Yes

样例输入 2

2 2
1 2
2 1

样例输出 2

No

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.