Discription

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 isreasonable if and only if the following condition is satisfied: For every threedistinct 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.

题目大意就是要你判断一下是否图中每个联通分量都是团(完全图)。这个暴力判断就行了,每条边至多会被判断一次,如果某条需要的边不存在那么就不合法。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=150005;
unordered_map<int,int> mmp[maxn];
unordered_map<int,int> ::iterator it;
int n,m,Q[maxn],H,T,uu,vv;
bool v[maxn];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d%d",&uu,&vv),mmp[uu][vv]=mmp[vv][uu]=1; for(int i=1,now;i<=n;i++) if(!v[i]){
Q[H=T=1]=i,v[i]=1;
while(H<=T){
now=Q[H++];
for(it=mmp[now].begin();it!=mmp[now].end();++it) if(!v[it->first]){
for(int j=1;j<=T;j++) if(!mmp[Q[j]].count(it->first)){
puts("NO");
return 0;
}
Q[++T]=it->first,v[Q[T]]=1;
}
}
} puts("YES");
return 0;
}

  

Graphs (Cakewalk) 1 B - medium的更多相关文章

  1. (转)Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph.

    Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph 2019-04-27 09:33:58 This ...

  2. tunning-Instruments and Flame Graphs

    On mac os, programs may need Instruments to tuning, and when you face too many probe messages, you'l ...

  3. 配置ASP.NET Web应用程序, 使之运行在medium trust

    这文章会向你展示, 怎么配置ASP.NET Web应用程序, 使之运行在medium trust.   如果你的服务器有多个应用程序, 你可以使用code access security和medium ...

  4. (谷歌浏览器等)解决css中点击input输入框时出现外边框方法【outline:medium;】

    问题:在使用谷歌浏览器,360浏览器时,点击input输入框会出现带颜色的外边框,如下图所示:

  5. Intel® Threading Building Blocks (Intel® TBB) Developer Guide 中文 Parallelizing Data Flow and Dependence Graphs并行化data flow和依赖图

    https://www.threadingbuildingblocks.org/docs/help/index.htm Parallelizing Data Flow and Dependency G ...

  6. 执行mount命令时找不到介质或者mount:no medium found的解决办法

    使用vmware时,在虚拟机设置里,设置CD/DVD为系统镜像,挂载时,有时会有找不到介质或者no medium found之类的提示. 根本原因是iso镜像并没有加载到虚拟机系统内. 解决办法: 首 ...

  7. VirtualBox:Fatal:Could not read from Boot Medium! System Halted解决措施

    打开VirtualBox加载XP虚拟机操作系统时,出现含有下面文字的错误:   Could not read from Boot Medium! System Halted   或下面图中所示错误: ...

  8. Developing a plugin framework in ASP.NET MVC with medium trust

    http://shazwazza.com/post/Developing-a-plugin-framework-in-ASPNET-with-medium-trust.aspx January 7, ...

  9. 特征向量-Eigenvalues_and_eigenvectors#Graphs

    https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors#Graphs A               {\displaystyle A} ...

随机推荐

  1. Python框架之Django学习笔记(十)

    又是一周周末,如约学习Django框架.在上一次,介绍了MVC开发模式以及Django自己的MVT开发模式,此次,就从数据处理层Model谈起. 数据库配置 首先,我们需要做些初始配置:我们需要告诉D ...

  2. BugKu 杂项-这么多数据包

    前边的都是些无关紧要,只要有点网络的基础我想应该都能懂,往下看,一直到NO104,这是在干什么? 源ip138一直向目标ip159发送syn握手包,想要建立连接,其实就是端口扫描,原理就是,想和你某个 ...

  3. Monkey日志信息的11种Event percentages

    我们查看官方文档,表里只给出了8种事件(可以看我上篇的翻译文档).但我们运行Monkey后,却发现有11种事件!最坑爹的是,在每种事件的百分比后面,他还不给注明是什么事件! 原来不同的Android ...

  4. thinkphp3.2接入支付宝支付接口(PC端)

    下载支付宝接口包    点击这里        提取密码:aryp 整个接口核心类文件 alipay.config.php是相关参数的配置文件 alipayapi.php 是支付宝接口入口文件 not ...

  5. 零基础学习 Python 之字符串

    初识字符串 维基百科对于字符串的定义式:字符串是由零个或者多个字符组成的有限串行.你之前学会敲的第一行 print 代码里的 "Hello World",就是一个字符串.字符串的本 ...

  6. Hadoop第三课

    1.3Hadoop基础知识 1.3.1术语解释 1.Hadoop1.0 • 第一代Hadoop,由分布式文件系统HDFS 和分布式计算框架MapReduce组成 • HDFS由一个NameNode和多 ...

  7. 深入学习之mysql(二)表的操作

    1.表:是数据库中的存储数据的基本单位,一个表包含若干个字段和值 2.创建表: CREATE TABLE 表名称 ( 字段名1 数据库类型1 [约束条件1], 字段名2 数据库类型2 [约束条件2], ...

  8. 基于 <tx> 和 <aop> 命名空间的声明式事务管理

    环境配置 项目使用SSH架构,现在要添加Spring事务管理功能,针对当前环境,只需要添加Spring 2.0 AOP类库即可.添加方法: 点击项目右键->Build Path->Add ...

  9. hdu6134[莫比乌斯反演] 2017多校8

    /*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...

  10. CTSC2018 旅游记

    我即使是死了,尸体烂在棺材里,也要用这腐朽的声音喊出: LJCCF!!!! DAY -3 体育中考AK了! 顿时感觉中考稳了(虽然竞赛已经特招) 新目标:我要用三种方式考上SZMS! DAY -1 成 ...