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也是朋友. 问你所给的图是 ...
随机推荐
- BZOJ 4089:[Sdoi2015]graft(SDOI 2015 Round 2 Day 2)
别人家的神选系列,我只会做这道题QAQ 题目描述: 给定一颗树,加上k条边,将n个点染色,相邻两点不同,记颜色为i的又ti个,求$$\frac{\sum_{i=1}^{n} \frac{ti}{i}} ...
- git的安装和环境配置过程(学习笔记)
1.安装git 官网下载:https://github.com(目前官网好像找不到了,但是妙味的视频里面是在官网下载的)https://git-for-windows.github.io/ (廖雪峰老 ...
- 【数据标识】iOS App下载渠道的统计需求
需求概述 我们现在有一个需求,某一个活动需要拉新所谓的拉新一般是推App下载,这个用户通过这个活动下载了App后,我们需要做到[在数据库中记录这个用户下载这个App是通过那个二维码渠道的,从效果上说, ...
- Android学习总结(一)——Activity的基本概念与Activity的生命周期
一.Activity的基本概念 Activity是Android的四大组件之一,它是一种可以包含用户界面的组件,主要用于和用户进行交互,比如打电话,照相,发送邮件,或者显示一个地图!Activity用 ...
- Python 3中字符串可以被改变吗?
Python 3中字符串可以被改变吗? 字符串有改变这个方法的:replace,比如: a = 'lkjhgfdsa' a.replace(') '123kjhgfdsa' #返回结果 从上面这个例子 ...
- 配置Server Side TAF
实验环境:Oracle 11.2.0.4 RAC 参考MOS文档: How To Configure Server Side Transparent Application Failover (文档 ...
- wemall app商城源码中基于JAVA通过Http请求获取json字符串的代码
wemall-mobile是基于WeMall的Android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.分享其中关于通过Http请求获取json字符串的代码供 ...
- 3856: Monster
3856: Monster Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 351 Solved: 161[Submit][Status][Discuss ...
- Java集合ArrayList源码解读
最近在回顾数据结构,想到JDK这样好的代码资源不利用有点可惜,这是第一篇,花了心思.篇幅有点长,希望想看的朋友认真看下去,提出宝贵的意见. :) 内部原理 ArrayList 的3个字段 priva ...
- php与mysql的常规使用
<?php header("Content-type:text/html;charset=GBK"); /* 通常,php网页中完成有关数据库的操作,首先,需要如下代码: $ ...