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

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 31 33 41 4

output

YES

input

4 43 12 33 41 2

output

NO

input

10 44 35 108 91 2

output

YES

input

3 21 22 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,否则不符合要求

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int dr[200000];
 4 vector<int>q[200000];
 5 int flag=0;
 6 int n,m;
 7 int vis[200000];
 8 queue<int>p;
 9 void dfs(int v)
10 {
11     if(vis[v]==1)
12     {
13         return;
14     }
15     vis[v]=1;
16   //  cout<<v<<endl;
17     p.push(v);
18     for(int i=0;i<q[v].size();i++)
19     {
20         int pos=q[v][i];
21         if(dr[pos]!=dr[v])
22         {
23            // flag=1;
24         }
25         if(vis[pos]==0)
26         {
27             //vis[pos]=1;
28             dfs(pos);
29         }
30     }
31 }
32 int main()
33 {
34     cin>>n>>m;
35     for(int i=1;i<=m;i++)
36     {
37         int s,e;
38         cin>>s>>e;
39         q[s].push_back(e);
40         q[e].push_back(s);
41         dr[s]++;
42         dr[e]++;
43     }
44     for(int i=1;i<=n;i++)
45     {
46         if(vis[i]==0)
47         {
48            // cout<<endl;
49             dfs(i);
50             int cnt=p.size();
51             while(!p.empty())
52             {
53                 int x=p.front();
54                 if(dr[x]!=cnt-1)
55                 {
56                     flag=1;
57                 }
58                 p.pop();
59             }
60         }
61     }
62     if(flag==1)
63     {
64         cout<<"NO"<<endl;
65     }
66     else
67     {
68         cout<<"YES"<<endl;
69     }
70     return 0;
71 }
时间: 2024-10-07 04:31:43

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

【树形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的整数倍,还要加上多少. 于是,我们现在只需要统计sigma((L+f(L,K))),最后除以K即可. 统计sigma(L)时,我们考虑计算每条边出现在了几条路径中,设u为edgei的子节点,那么这条边对答案的贡献就是siz(u)*(n-siz(u)),siz(u)为u的子树大小. 统计sigma(f(L,K))时,我们需要dp出

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 battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if

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

Description Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) B. T-Shirt Hunt

B. T-Shirt Hunt time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participant

Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记

题目链接:C. Producing Snow 题意:给两个数组v[N],T[N],v[i]表示第i天造的雪,T[i],表示第i天的温度,一堆雪如果<=T[i],当天就会融完,否则融化T[i],要求输出每天的融雪总量. 题解:我对T数组求个前缀和,就可以二分找到每堆雪在那一天(pos)融化,余下的要加进答案中ans[i],然后用一个an数组在a[i]+1,a[pos]-1,最后求再求一次前缀和. ans[i]再加上an[i]*t[i].每次操作二分logn,N次操作.复杂度O(nlogn) #in

Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2)

A. Tritonic Iridescence 题解:分类讨论.注意题目要求,至少有两种方案. 1 #pragma warning(disable:4996) 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 9 int n, m; 10 stri

Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) C. Stairs and Elevators【二分查找】

In the year of 30XX30XX participants of some world programming championship live in a single large hotel. The hotel has nn floors. Each floor has mm sections with a single corridor connecting all of them. The sections are enumerated from 11 to mm alo

【枚举】【二分】【推导】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担给它们,要求每台服务器承担的资源需求不超过其所能提供的资源需求.给定一种合法的方案,每台服务器要么没有被分配给任何一个服务,或者被分配给其中一个服务. 对服务器按能提供的资源从小到大排序.枚举给S1分配的服务器数量i,然后在a数组中二分,就可以得到给S1提供的是哪i台服务器,它们占据了a数组中连续的

Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) E. Prairie Partition 二分+贪心

E. Prairie Partition It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2k - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2k. Let's call that representation prairie partition of x. For example, the p