CF771A.Bear and Friendship Condition

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).

There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves.

Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.

For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.

Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.

熊 Limak 正在研究一个社交网络。该网络的核心功能是:两名成员可以成为朋友(此后他们便能相互交谈并分享有趣的图片)。

共有 nn 名成员,编号为 11 到 nn。其中有 mm 对成员互为朋友。显然,一名成员不能与自己成为朋友。

用 A-B 表示成员 A 与成员 B 是朋友。Limak 认为,当且仅当满足以下条件时,该网络才是“合理的”:对任意三个互不相同的成员(X, Y, Z),若 X-Y 且 Y-Z,则也必须有 X-Z。

例如:若 Alan 与 Bob 是朋友,且 Bob 与 Ciri 是朋友,则 Alan 与 Ciri 也必须是朋友。

你能帮助 Limak 判断该网络是否合理吗?请据此输出 "YES" 或 "NO"(不含引号)。

输入格式

The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, ) — the number of members and the number of pairs of members that are friends.

The i-th of the next m lines contains two distinct integers a__i and b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i). Members a__i and b__i are friends with each other. No pair of members will appear more than once in the input.

输入的第一行包含两个整数 nn 和 mm(3 ≤ n ≤ 150 0003 ≤ n ≤ 150\,000,),分别表示成员数量和互为朋友的成员对数。

接下来的 mm 行中,第 ii 行包含两个互异的整数 aia_i 和 bib_i(1 ≤ ai, bi ≤ n1 ≤ a_i,\,b_i ≤ n,且 ai ≠ bia_i ≠ b_i),表示成员 aia_i 与 bib_i 彼此是朋友。输入中不会重复出现同一对成员。

输出格式

If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).

如果给定的网络是合理的,则在一行中输出 “YES”(不带引号)。否则,在一行中输出 “NO”(不带引号)。

输入输出样例

  • 输入#1

    4 3
    1 3
    3 4
    1 4

    输出#1

    YES
  • 输入#2

    4 4
    3 1
    2 3
    3 4
    1 2

    输出#2

    NO
  • 输入#3

    10 4
    4 3
    5 10
    8 9
    1 2

    输出#3

    YES
  • 输入#4

    3 2
    1 2
    2 3

    输出#4

    NO

说明/提示

The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.

下图展示了第一个样例(左侧)和第二个样例(右侧)的情形。每条边表示两名互为朋友的成员。第二个样例的答案为“NO”,因为成员 (2, 3) 是朋友,且成员 (3, 4) 也是朋友,但成员 (2, 4) 却不是朋友。

输入解题思路,AI测评打分。不知道怎么写?

首页