题意:如果1认识2,2认识3,必须要求有:1认识3.如果满足上述条件,输出YES,否则输出NO.

思路:显然如果是一个完全图就输出YES,否则就输出NO,如果是无向完全图则一定有我们可以用dfs来书边和点

n个节点的有向完全图边数为e=n*(n-1)

代码:

#include <bits/stdc++.h>
#define maxn 150000
#define ll long long
using namespace std; vector <int> k[maxn+];
bool visit[maxn+];
int t; void dfs(int x,int &v,int &e)
{
assert(!visit[x]);
v++;
visit[x]=true;
e+=k[x].size();
for(int i=;i<k[x].size();i++)
{
if(visit[k[x][i]]==)
dfs(k[x][i],v,e);
}
} int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=;i<m;i++)
{
int x,y;
scanf("%d %d",&x,&y);
k[x].push_back(y);
k[y].push_back(x);
}
for(int i=;i<=n;i++)
{
if(!visit[i])
{
int v=,e=;
dfs(i,v,e);
if(e!=(long long) v*(v-))
{
cout<<"NO"<<endl;
return ;
}
}
}
cout<<"YES"<<endl;
}
return ;
}

CF #405 (Div. 2) B. Bear ad Friendship Condition (dfs+完全图)的更多相关文章

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

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

  4. Codeforces791 B. Bear and Friendship Condition

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

  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. Codeforces_791_B. Bear and Friendship Condition_(dfs)

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

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

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

  8. 【CF771A】Bear and Friendship Condition

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

  9. 【codeforces 791B】Bear and Friendship Condition

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

随机推荐

  1. 实例了解js面向对象的封装和继承等特点

    1.面向对象特点 相比之前按照过程式写法,面向对象有以下几个特点; 1.抽象:抓住核心问题,就是将很多个方法放在一个对象上.对象由属性和方法组成,属性就是我们定义的变量,它是静态的:方法就是行为操作, ...

  2. PHP学习2 — PHP Cookie 与 Session

    PHP Cookies cookie 常用于识别用户.cookie 是服务器留在用户计算机中的小文件.每当相同的计算机通过浏览器请求页面时,它同时会发送 cookie.通过 PHP,您能够创建并取回 ...

  3. 【CNMP系列】CNMP之路,系统起步。

    简单的来理解,我所说的CNMP,不是CNM+P,而是CentOs+Nginx+MySql+PHP,也可以单纯的理解为LNMP,但是系统是我们自己选的,虽说是Linux的一个分支,但我就喜欢CentOs ...

  4. fiddler介绍

    先看fiddler 的使用界面和各模块的功能介绍 1请求列表:请求列表中包含了许多信息,从左至右依次为,#(序列号),Result(结果状态码),Prottocol(请求的协议),Host(请求的主机 ...

  5. angular.js之作用域scope'@','=','&'

    <!doctype html> <html ng-app='myApp'> <head> </head> <body> <script ...

  6. oracle commond

    常用commond alter user scott account unlock; --解锁账号 alter user scott identified by new_pwd; --设置密码 lsn ...

  7. 类中的两大类(string类、math类)的应用

    类是我们在学习C#的过程中很关键也是特别容易让人蒙逼得地方,类的应用直接可以调用它的属性和方法来进行判断和验证 string类(也叫字符串类) C#中的String类很有用,下面是一些它的常用方法的总 ...

  8. HTML5之多媒体

    概览 html5新增了两个关于多媒体的元素:video和audio,前者是用于视频,后者用于音频.而他们使用非常简单 <audio src="xhn.mp3" control ...

  9. C#知识整理笔记

    这里简单介绍了一些常用的属性,以及一些术语的解释和举例说明,不太全面,希望读者多多补充. 1.重载:函数名相同,参数的个数或参数类型不同; public void MyDog(string s); p ...

  10. Servlet中编码在过滤器中的使用

    1.先配置web.xml ->配置过滤器 // filter-class 为写的过滤器类 实现 Filter 接口 <filter> <filter-name>Encod ...