CF #405 (Div. 2) B. Bear ad Friendship Condition (dfs+完全图)
题意:如果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+完全图)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces791 B. Bear and Friendship Condition
B. Bear and Friendship Condition time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces 791B. Bear and Friendship Condition 联通快 完全图
B. Bear and Friendship Condition time limit per test:1 second memory limit per test:256 megabytes in ...
- 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 ...
- CodeForce-791B Bear and Friendship Condition(并查集)
Bear Limak examines a social network. Its main functionality is that two members can become friends ...
- 【CF771A】Bear and Friendship Condition
题目大意:给定一张无向图,要求如果 A 与 B 之间有边,B 与 C 之间有边,那么 A 与 C 之间也需要有边.问这张图是否满足要求. 题解:根据以上性质,即:A 与 B 有关系,B 与 C 有关系 ...
- 【codeforces 791B】Bear and Friendship Condition
[题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是 ...
随机推荐
- LNMP系统服务搭建过程详解
和LAMP不同的是LNMP中的N指的是Nginx(类似于Apache的一种web服务软件)其他都一样.目前这种环境应用的也是非常之多.Nginx设计的初衷是提供一种快速高效多并发的web服务软件.在静 ...
- Tree on the level UVa122
很单纯的树的遍历,但是输入和方向好麻烦!!下面给出代码,题目来自UVa 122 #include<cstdio> #include<cstring> #include<v ...
- eclipse+HBASE开发环境搭建(已实践)
开发准备: jdk1.8.45 hbase-1.2.2(windows下和linux个留一份) hadoop-2.7.2(linux一份) Linux系统(centos或其它) Hadoop安装环境 ...
- poj 2236
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25817 Accepted: 107 ...
- FineUIMvc随笔(5)UIHelper是个什么梗?
声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. UIHelper.Result 在 FineUIMvc 的每一个 HttpPost 的控制器方法里面,你都会看到 UIHelpe ...
- Bat小试牛刀
前天版本发布后同事才发现有点小瑕疵,当然这是前期的设计和测试没到位造成的.撇开这些不说,我想说的是知识面广一点,做起事情来可能更得心应手些. 大致是这样的,由于版本的迭代,导致发布的程序只能清除一部分 ...
- Java中的for each实现原理与坑
文章转载自「开发者圆桌」一个关于开发者入门.进阶.踩坑的微信公众号 在Java中,遍历集合和数组一般有以下三种形式: for (int i = 0; i < list.size(); i++) ...
- 学习HTML5一周的收获4
/* [CSS常用文本属性] * 1.字体.字号: font-weight:字体的粗细,可选属性值:bold加粗 lighter细体 100~900数值(400正常,700 bold) fo ...
- 大富豪APK安卓客户端的反编译修改和重新打包
大富豪APK安卓客户端的反编译修改和重新打包 修改安装我们需要几个工具 DFH_3.4.X (用于修改客户端) dnsPy (用于修改.dll文件) 大富豪加解密.exe ( 用于加 ...
- conky 1.10以后的新配置格式
包装 config conky.config = { ... } 包装 TEXT conky.text = [[ ... ]] 每个 config 选项的变量和取值之间插入 "=" ...