Bear and Friendship Condition

time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

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.

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

 #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
int pre[];
int Find(int x){
return x==pre[x]?x:pre[x]=Find(pre[x]);
}
void mix(int x,int y){
int xx=Find(x),yy=Find(y);
if(xx!=yy){
pre[xx]=yy;
}
}
LL t[];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
pre[i]=i;
}
for(int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
mix(x,y);
}
for(int i=;i<=n;i++){
t[Find(i)]++;
}
LL sum=;
for(int i=;i<=n;i++){
if(t[i]!=&&t[i]!=){
sum+=(t[i]*(t[i]-)/);
}
}
if(sum!=m){
printf("NO\n");
}
else{
printf("YES\n");
}
return ;
}

Bear and Friendship Condition-HZUN寒假集训的更多相关文章

  1. Codeforces 791B Bear and Friendship Condition(DFS,有向图)

    B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...

  2. codeforces round #405 B. Bear and Friendship Condition

    B. Bear and Friendship Condition time limit per test 1 second memory limit per test 256 megabytes in ...

  3. Codeforces791 B. Bear and Friendship Condition

    B. Bear and Friendship Condition time limit per test 1 second memory limit per test 256 megabytes in ...

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

  5. Codeforces 791B. Bear and Friendship Condition 联通快 完全图

    B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...

  6. CodeForce-791B Bear and Friendship Condition(并查集)

    Bear Limak examines a social network. Its main functionality is that two members can become friends ...

  7. CF #405 (Div. 2) B. Bear ad Friendship Condition (dfs+完全图)

    题意:如果1认识2,2认识3,必须要求有:1认识3.如果满足上述条件,输出YES,否则输出NO. 思路:显然如果是一个完全图就输出YES,否则就输出NO,如果是无向完全图则一定有我们可以用dfs来书边 ...

  8. 食物链-HZUN寒假集训

    食物链 总时间限制: 1000ms 内存限制: 65536kB 描述 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动 ...

  9. 【CF771A】Bear and Friendship Condition

    题目大意:给定一张无向图,要求如果 A 与 B 之间有边,B 与 C 之间有边,那么 A 与 C 之间也需要有边.问这张图是否满足要求. 题解:根据以上性质,即:A 与 B 有关系,B 与 C 有关系 ...

  10. 【codeforces 791B】Bear and Friendship Condition

    [题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是 ...

随机推荐

  1. django练习——博客系统优化

    一直准备使用Django搭建一个个人网站,最近终于开始动手,上周已经完成了基本博客功能的搭建(http://blog.csdn.net/hcx25909/article/details/2460133 ...

  2. 1013. Battle Over Cities (25)

    题目如下: It is vitally important to have all the cities connected by highways in a war. If a city is oc ...

  3. C语言实现万年历

    给出你想知道的年份,便可以计算出该年对应的每个月每个日所对应的星期数,是不是感觉很好玩 ? #include <stdio.h> #include<stdlib.h> long ...

  4. 用 boost::multi_index 管理玩家

    用 boost::multi_index 管理玩家(金庆的专栏)网游服务器上的玩家集合需要多种索引:如用ID查找,角色名查找, 用登录时分配的会话ID查找.用boost::multi_index进行玩 ...

  5. NSString的几种常用方法—韩俊强博…

    要把 "2011-11-29" 改写成 "2011/11/29"一开始想用ios的时间格式,后来用NSString的方法搞定. 1.创建NSString字符串 ...

  6. UVa - 1618 - Weak Key

    Cheolsoo is a cryptographer in ICPC(International Cryptographic Program Company). Recently, Cheolsoo ...

  7. PCA与特征选取

    一.什么是PCA PCA,即PrincipalComponents Analysis,也就是主成份分析: 通俗的讲,就是寻找一系列的投影方向,高维数据按照这些方向投影后其方差最大化(方差最大的即是第一 ...

  8. 基于Struts+Hibernate开发过程中遇到的错误

    1.import  javax.servlet.http.HttpServletRequest 导入包出错 导入包出错,通常是包未引入,HttpServletRequest包是浏览器通过http发出的 ...

  9. Ext.Net 1.x_Ext.Net.GridPanel嵌套Checkbox

    解决办法:拼接HTML var tplchecked = '<input type="checkbox" {0}>'; var IsChecked = function ...

  10. .NET(C#)连接各类数据库代码-集锦

    1.C#连接连接Access 复制代码代码如下: using System.Data;   using System.Data.OleDb;   ..   string strConnection=& ...