题意:如果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. angular : direative : autoResize textarea auto resize

    今天为大家推出自己的auto resize 指令功能. 目的:解决textarea在给height的问题. 参考源码:http://monospaced.github.io/angular-elast ...

  2. FFmpeg入门,简单播放器

    一个偶然的机缘,好像要做直播相关的项目 为了筹备,前期做一些只是储备,于是开始学习ffmpeg 这是学习的第一课 做一个简单的播放器,播放视频画面帧 思路是,将视频文件解码,得到帧,然后使用定时器,1 ...

  3. 两款【linux字符界面下】显示【菜单】,【选项】的powershell脚本模块介绍

    两款[linux字符界面下]显示[菜单],[选项]的powershell脚本模块介绍 powershell linux  ps1 menu choice Multiselect 传教士 菜单 powe ...

  4. Python学习--23 第三方库

    本文将介绍python里常用的模块.如未特殊说明,所有示例均以python3.4为例: $ python -V Python 3.4.3 网络请求 urllib urllib提供了一系列用于操作URL ...

  5. Think PHP 基础

    ThinkPHP 一.什么框架: 一堆代码的集合,里边有变量.函数.类.常量,里边也有许多设计模式MVC.AR数据库.单例等等. 框架可以节省我们50-60%的工作量,我们全部精力都集中在业务层次. ...

  6. Playground 你不知道的小技巧, CoreData 的使用

    Playground 的出现无疑是大大的提高了开发效率,可以节省大量的编译时间. 这里介绍在 Playground 中使用 CoreData 的小技巧. 我们新建一个工程 iOS 项目工程. 点击Fi ...

  7. 多线程爬坑之路--并发,并行,synchonrized同步的用法

    一.多线程的并发与并行: 并发:多个线程同时都处在运行中的状态.线程之间相互干扰,存在竞争,(CPU,缓冲区),每个线程轮流使用CPU,当一个线程占有CPU时,其他线程处于挂起状态,各线程断续推进. ...

  8. 【2-23】分支语句(switch…case)及循环语句

    Switch-case分支语句与if语句作用相同,但需将情况都罗列出比较麻烦所以不常用. 其基本结构是: Switch(一个变量值) { Case 值1:要执行的代码段:break; Case 值2: ...

  9. ASP渲染下拉框使时间依次减少

    <%    x=year(now())    y=year(now())-1    Do While  y>2002%><li><a href="#201 ...

  10. 1179: [Apio2009]Atm

    1179: [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 1629  Solved: 615[Submit][Status ...