Description

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

Input

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 ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai and bi are friends with each other. No pair of members will appear more than once in the input.

Output

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

Examples
input
4 3
1 3
3 4
1 4
output
YES
input
4 4
3 1
2 3
3 4
1 2
output
NO
input
10 4
4 3
5 10
8 9
1 2
output
YES
input
3 2
1 2
2 3
output
NO
Note

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.

题意:给我们一种朋友关系,必须是a和b是朋友,b和c是朋友,c和a是朋友才满足要求

解法:对于每一个联通块里面的点,其必须与其他在联通块的点都相连,就是联通块的点个数-1,否则不符合要求

 #include<bits/stdc++.h>
using namespace std;
int dr[];
vector<int>q[];
int flag=;
int n,m;
int vis[];
queue<int>p;
void dfs(int v)
{
if(vis[v]==)
{
return;
}
vis[v]=;
// cout<<v<<endl;
p.push(v);
for(int i=;i<q[v].size();i++)
{
int pos=q[v][i];
if(dr[pos]!=dr[v])
{
// flag=1;
}
if(vis[pos]==)
{
//vis[pos]=1;
dfs(pos);
}
}
}
int main()
{
cin>>n>>m;
for(int i=;i<=m;i++)
{
int s,e;
cin>>s>>e;
q[s].push_back(e);
q[e].push_back(s);
dr[s]++;
dr[e]++;
}
for(int i=;i<=n;i++)
{
if(vis[i]==)
{
// cout<<endl;
dfs(i);
int cnt=p.size();
while(!p.empty())
{
int x=p.front();
if(dr[x]!=cnt-)
{
flag=;
}
p.pop();
}
}
}
if(flag==)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
return ;
}

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B的更多相关文章

  1. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  2. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  3. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  4. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

  5. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)

    A 模拟 B 发现对于每个连通块,只有为完全图才成立,然后就dfs C 构造 想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难.. 考虑对于顺序枚举每一个NO/YES, ...

  6. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)A B C 水 并查集 思路

    A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...

  7. 【构造】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) A. Bear and Different Names

    如果某个位置i是Y,直接直到i+m-1为止填上新的数字. 如果是N,直接把a[i+m-1]填和a[i]相同即可,这样不影响其他段的答案. 当然如果前面没有过Y的话,都填上0就行了. #include& ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) E

    Description Bear Limak prepares problems for a programming competition. Of course, it would be unpro ...

  9. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) D

    Description A tree is an undirected connected graph without cycles. The distance between two vertice ...

  10. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

    Description In the army, it isn't easy to form a group of soldiers that will be effective on the bat ...

随机推荐

  1. Zip加密解密

    Zip加密解密方法: 1.winzipaes http://blog.csdn.net/zhyh1986/article/details/7724229 2.zip4j http://blog.csd ...

  2. cocos2d-x(vs2012)环境搭建(第一篇)[版本号:cocos2d-x-3.1.1]

    1.下载资源 下载cocos2d-x包V3.1.1,下载戳这里: http://www.cocos2d-x.org/download vs2012下载戳这里: http://www.xiazaiba. ...

  3. LeetCode(66)题解: Plus One

    https://leetcode.com/problems/plus-one/ 题目: Given a non-negative number represented as an array of d ...

  4. Zed Shaw:一位老程序员的建议

    Advice from an Old Programmer 原文:Zed Shaw,译文:外刊IT评论 导读:原文作者Zed Shaw是一位作家.软件开发人员.音乐人(下文中提到吉他手),于2010年 ...

  5. x$kccle视图深入剖析

       今天是2014-05-27,实在无聊顺便研究一下x$kccle的内容吧.例如以下所有是自己分析和实验结果,真实可靠.   1.怎样获得v$log的底层表?我们能够通过autotrace完毕查看如 ...

  6. python模拟登陆discuz论坛

    #! /usr/bin/env python # -*- coding: utf-8 -*- import urllib2, urllib, cookielib, re, time class Rob ...

  7. JavaScript数组遍历:for、foreach、for in、for of、$.each、$().each的区别

    一.for Javascript中的for循环,它用来遍历数组 var arr = [1,2,3,4] for(var i = 0 ; i< arr.length ; i++){ console ...

  8. codeforces B. Balls Game 解题报告

    题目链接:http://codeforces.com/problemset/problem/430/B 题目意思:给出用不多于k种颜色对n个球的染色情况,以及手中的唯一一个球的颜色.初始时,连续的相同 ...

  9. 转:Oracle客户端NLS_LANG参数的设置详解

    原文:http://database.51cto.com/art/201107/279361.htm 我们知道,Oracle客户端语言支持可以通过NLS_LANG参数的设置来完成,不同的系统平台上NL ...

  10. ssl原理及应用

    今天学习网络通信,看到使用ssl(Secure Sockets Layer)进行加密,由于对ssl只是有些概念上的了解,对于具体应用原理.过程和如何使用不慎了解,于是学习了一番,总结如下: 1. 为什 ...