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. dsBlog_杂类

    C++,MFC的综合类的博客. 1. http://www.cnblogs.com/mfryf/category/354043.html

  2. Python 004- 利用图灵小机器人来搭建微信聊天自动回复机器人

    实现步骤: 1.获取微信的使用权,即python脚本能控制微信收发信息. 2.python脚本收到聊天信息后,要对该信息进行处理,返回机器人的回应信息. 一二两步要用到wxpy库里的各种组件来收发信息 ...

  3. 两个月刷完Leetcode前400题经验总结

    更新:气死了,挂个傻逼: 每次做个分享.组织个活动,就会有一些傻逼冒泡生怕别人不知道他是傻逼,气死我了!自己好好看看非法集资的概念,我办这个活动,一分钱都没收,入群99元是督促大家完成刷题任务,最后完 ...

  4. Django 之ORM操作

    1.什么是ORM? 全称关系对象映射Object Relational Mapping(简称ORM),是通过描述面向对象与数据库之间的对应的元数据,将对象持久化的更新到数据库中. 有了ORM,就不需要 ...

  5. Phoenix put the sql back in NoSql

    Overview | Apache Phoenix http://phoenix.apache.org/index.html Apache Phoenix enables OLTP and opera ...

  6. sbt is a build tool for Scala, Java, and more

    http://www.scala-sbt.org/0.13/docs/index.html sbt is a build tool for Scala, Java, and more. It requ ...

  7. 通过ODC方法改善软件测试:3个案例研究

    正交缺陷分类法(ODC)是一种用于分析软件缺陷的归类方法.它可以结合软件开发过程的一系列数据分析技术,为测试组织提供了一个强大的针对开发过程和软件产品的评估方法.在本篇文章中,会列举三个案例研究来说明 ...

  8. hdu 1166 敌兵布阵 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题目意思:给出 N 个数你,通过对某些数进行更改(或者 + 或者 -),当输入的是 Query ...

  9. html5--6-3 CSS语法2

    html5--6-3 CSS语法2 实例 div包含p和h标签的时候可以,但是p标签包含h标签的时候不可以  学习要点 掌握引入外部样式表方法 插入样式的三种方法 内联样式表(行内) 内部样式表(st ...

  10. 【转】maven的安装、配置以及下载jar包

    原文地址:https://blog.csdn.net/qq_40673345/article/details/79015456 1.下载maven的压缩包,并解压到除了C盘里的maven文件夹中 2. ...