题意:如果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. android学习3——长宽的单位问题dp,px,dpi

    android设备的单位px,pt,dp,sp 分辨率 先通俗说下分辨率的概念.可以把屏幕想想成一个个正方形格子组成的.如果横向有1280个格子,竖向有720个格子.那么分辨率就是1280*720.这 ...

  2. 以setTimeout来聊聊Event Loop

    平时的工作中,也许你会经常用到setTimeout这个方法,可是你真的了解setTimeout吗?本文想通过总结setTimeout的用法,顺便来探索javascript里面的事件执行机制. setT ...

  3. python爬虫利器Selenium使用详解

    简介: 用pyhon爬取动态页面时普通的urllib2无法实现,例如下面的京东首页,随着滚动条的下拉会加载新的内容,而urllib2就无法抓取这些内容,此时就需要今天的主角selenium. Sele ...

  4. Delphi中TApplication详解

    转自:http://blog.sina.com.cn/s/blog_4d6f55d90100bmv9.html TApplication是用于Delphi应用程序的类型,该类在单元forms中声明.T ...

  5. 编程思想之——"人是活的,程序是死的"

    "人是活的,程序是死的"这句话我时常提起,可能很多人不是很理解我为什么会这样说,下面我就简单来谈谈我对这句话的理解. 1.不要因为技术而技术,技术选型的初衷是需求. 现在很多人在做 ...

  6. EFcore与动态模型(三)

    紧接着上面的内容,我们继续看下动态模型页面交互实现方式,内容如下: 1,如何实现动态表单 2,如何接收表单数据并绑定到动态模型上 一.如何实现动态表单 由于模型信息都是后台自定义配置的,并不是固定不变 ...

  7. 【2017-2-17】C#基础 - 定义变量,输入输出

    1.初学C#. C#是专门为.NET的应用而开发的语言,他吸收了C++.Visual Basic.Delphi.Java等语言的优点,提高了程序开发的效率. 2.Visual Studio.NET的集 ...

  8. 循环神经网络(RNN)模型与前向反向传播算法

    在前面我们讲到了DNN,以及DNN的特例CNN的模型和前向反向传播算法,这些算法都是前向反馈的,模型的输出和模型本身没有关联关系.今天我们就讨论另一类输出和模型间有反馈的神经网络:循环神经网络(Rec ...

  9. Visual Studio 20周年软件趋势随想

    从2002年开始,.net让开发人员能快速构建和部署应用程序,便捷的开发windows和web服务器应用,同时著名的hacker Miguel de Icaza ,Miguel 为了GNOME项目启动 ...

  10. JavaScript数据结构——栈的实现

    栈(stack)是一种运算受限的线性表.栈内的元素只允许通过列表的一端访问,这一端被称为栈顶,相对地,把另一端称为栈底.装羽毛球的盒子是现实中常见的栈例子.栈被称为一种后入先出(LIFO,last-i ...