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
  1. 4 3
    1 3
    3 4
    1 4
Output
  1. YES
Input
  1. 4 4
    3 1
    2 3
    3 4
    1 2
Output
  1. NO
Input
  1. 10 4
    4 3
    5 10
    8 9
    1 2
Output
  1. YES
Input
  1. 3 2
    1 2
    2 3
Output
  1. 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.

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

  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int maxn=150005;
  5. unordered_map<int,int> mmp[maxn];
  6. unordered_map<int,int> ::iterator it;
  7. int n,m,Q[maxn],H,T,uu,vv;
  8. bool v[maxn];
  9. int main(){
  10. scanf("%d%d",&n,&m);
  11. for(int i=1;i<=m;i++) scanf("%d%d",&uu,&vv),mmp[uu][vv]=mmp[vv][uu]=1;
  12.  
  13. for(int i=1,now;i<=n;i++) if(!v[i]){
  14. Q[H=T=1]=i,v[i]=1;
  15. while(H<=T){
  16. now=Q[H++];
  17. for(it=mmp[now].begin();it!=mmp[now].end();++it) if(!v[it->first]){
  18. for(int j=1;j<=T;j++) if(!mmp[Q[j]].count(it->first)){
  19. puts("NO");
  20. return 0;
  21. }
  22. Q[++T]=it->first,v[Q[T]]=1;
  23. }
  24. }
  25. }
  26.  
  27. puts("YES");
  28. return 0;
  29. }

  

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. TypeError: cannot perform reduce with flexible type

    想要解决这个错误,最好先明白numpy数据类型的dtype转换 生成一个浮点数组 a=np.random.random(4) 输出 a array([0.0945377,0.52199916,0.62 ...

  2. 驱动模块 .ko

    模块: 模块机制,作用搞高LINUX操作系统的扩充性. 1. 模块概念: 1.动态可加载内核模块LKM 2.内核空间运行 3.是不是一执行文件,是一个没有经过链接,不能独立运行的一个目标文件(.c-& ...

  3. loj2065 「SDOI2016」模式字符串

    ref不是太懂 #include <iostream> #include <cstring> #include <cstdio> using namespace s ...

  4. 8、HTML DOM总结

    1.HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model):HTML DOM 模型被构造为对象的树. 2.DOM 方法 < ...

  5. linq本质扩展方法+lambda表达式

    string[] names = { "aa","bb","cc","dd"}; /* IEnumerable<s ...

  6. rm 、git rm 、git rm --cached的区别

    rm 删除文件 git rm git rm 当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用git rm git rm file = rm file+ git add f ...

  7. 获取完整的URL request.getQueryString()

    public String codeToString(String str) { String strString = str; try { byte tempB[] = strString.getB ...

  8. spring IOC注解方式详解

    本文分为三个部分:概述.使用注解进行属性注入.使用注解进行Bean的自动定义. 一,概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以 ...

  9. 体验devstack安装openstack

    由于公司制度,工作环境是不能直接上网的,所以在工作时间从没有体验过devstack或者其他联网方式安装openstack. 因自己购置了一台不错的主机,因而决定尝试安装一番,经过一段为期不短的内心极度 ...

  10. Sql数据表中的关系