题意:如果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. JTextArea与TextArea自动换行和滚动条的区别对比

    最近在用Java写一个仿记事本的程序,但是发现用JTextArea写的效果有点差,但是用TextArea自动换行并不那么方便,经过对比和实践,我也发现自己对这两个标签认识存在不足,下面就来讨论一下他们 ...

  2. Nginx http 500错误分析及解决方法

      出现场景:   在用nginx做负载均衡服务器对系统做并发测试,并发量比较大时Nginx会报出Http 500错误     报错原因:   访问量大的时候,由于系统资源限制,而不能打开过多的文件 ...

  3. async/await与promise(nodejs中的异步操作问题)

    此文只是粗略介绍使用方法,欲了解核心概念请参考官方文档或其他资料. 举例写文章详情页面的时候的一个场景:首先更改文章详情中的 PV,然后读取文章详情,然后根据文章详情中文章 Id 查阅该文章评论和该文 ...

  4. 搭建windows环境下(nginx+mysql+php)开发环境

    搭建windows环境下(nginx+mysql+php)开发环境   1. 所需准备应用程序包        1.1 nginx 程序包nginx-1.0.4.zip或其他版本(下载地址: http ...

  5. 【Java集合类】ArrayList详解 (JDK7)

    相信对于使用过Java的人来说,ArrayList这个类大家一定不会陌生. 数据结构课上讲过, Array是数组,它能根据下标直接找到相应的地址,所以索引速度很快,但是唯一的缺点是不能动态改变数组的长 ...

  6. 深入Redux架构

    关于redux 之前写了一篇通过一个demo了解Redux,但对于redux的核心方法没有进行深入剖析,在此重新总结学习,完整的代码看这里.(参考了React 技术栈系列教程) 什么情况需要用redu ...

  7. Pascal's Triangle II leetcode

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  8. 基于 Koa平台Node.js开发的KoaHub.js的静态服务器重写和索引代码

    koa-static-server Static file serving middleware for koa with directory, rewrite and index support k ...

  9. 本机安装mysql服务,步骤教程(另附SQLyog和Navicat工具)

    因为这段时间不是装系统就是换硬盘,导致装了还几次MySql,每次都记不住都要上网找教程,着实麻烦,所以这次干脆直接写到博客上好了,便于自己也便于他人: 百度云:http://pan.baidu.com ...

  10. fopen参数

    此文用于学习交流 原作:http://www.cnblogs.com/ai616818/archive/2012/04/26/2470918.html FILE * fopen(const char ...