Brain Network (easy)
One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of n brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:
- It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains).
- There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false.
If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) denoting the number of brains (which are conveniently numbered from 1 to n) and the number of brain connectors in the nervous system, respectively. In the next m lines, descriptions of brain connectors follow. Every connector is given as a pair of brains a b it connects (1 ≤ a, b ≤ n, a ≠ b).
The output consists of one line, containing either yes or no depending on whether the nervous system is valid.
4 4
1 2
2 3
3 1
4 1
no
6 5
1 2
2 3
3 4
4 5
3 6
yes
分析:判断联通和环;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,vis[maxn],cnt;
vi a[maxn];
void dfs(int now,int pre)
{
vis[now]=;cnt++;
for(int x:a[now])
{
if(vis[x]&&x!=pre)exit(*puts("no"));
if(!vis[x])dfs(x,now);
}
}
int main()
{
int i,j,k,t;
scanf("%d%d",&n,&m);
rep(i,,m)scanf("%d%d",&j,&k),a[j].pb(k),a[k].pb(j);
dfs(j,);
if(cnt==n)puts("yes");else puts("no");
//system ("pause");
return ;
}
Brain Network (easy)的更多相关文章
- Brain Network (easy)(并查集水题)
G - Brain Network (easy) Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- codeforces 690C1 C1. Brain Network (easy)(水题)
题目链接: C1. Brain Network (easy) time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Brain Network (medium)
Brain Network (medium) Further research on zombie thought processes yielded interesting results. As ...
- Brain Network (medium)(DFS)
H - Brain Network (medium) Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d &am ...
- codeforces 690C2 C2. Brain Network (medium)(bfs+树的直径)
题目链接: C2. Brain Network (medium) time limit per test 2 seconds memory limit per test 256 megabytes i ...
- CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)
题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...
- codeforces 690C3 C3. Brain Network (hard)(lca)
题目链接: C3. Brain Network (hard) time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Codeforces 690 C3. Brain Network (hard) LCA
C3. Brain Network (hard) Breaking news from zombie neurology! It turns out that – contrary to prev ...
随机推荐
- RecyclerView.Adapter
RecyclerView无需多说,是用于替代ListView的新控件.它的适配器在于灵活. 现在有一个需求:需要RecyclerView的item支持点击事件,并且下拉到最后时,显示ProgressB ...
- LoadRunner学习知多少--IP欺骗使用
使用IP欺骗功能时,需要将系统防火墙,杀毒软件关闭(如果有影响的话) 一.为什么要设置IP欺骗 1. 当某个IP的访问过于频繁,或者访问量过大时,服务器会拒绝访问请求,这时候通过IP欺骗可以增加访问频 ...
- JS杂记
jQuery(function($) {等于<body onload ='rickk()'>function rickk() }
- pureMVC java版搭建流程
转自:http://blog.csdn.net/sutaizi/article/details/6588004 pureMVC 是一个轻量级的框架 它在 flex中非常流行(和cairngorm差不多 ...
- 当list做gridview的数据源时,可以用泛型来对list进行排序
当list做gridview的数据源时,可以用泛型来对list进行排序 ,代码如下 var temps = from t in list orderby t.paymentAmount descend ...
- AOP与动态代理有什么联系
曾遇到“AOP与动态代理有什么联系”的问题,现把个人观点整理如下: 我觉得,动态代理是AOP的主要实现手段之一,AOP是动态代理的一种应用深化 AOP是一种思想,或者是方法论,类似OOP,是OOP的有 ...
- iptables防火墙详解
iptables常用命令 iptables -nv -L 查看iptables列表 iptables -F 清空iptables规则 iptables-save > /etc/sysconfig ...
- Linux 配置VNC远程桌面
X11 提供的 display manager 为 xdm ,而著名的 KDE 与 GNOME 也都有自己的 display manager 管理程序,分别是 kdm 与 gdm .你可以透过三者中任 ...
- perl的Getopt::Long和pod::usage ?
来源: http://www.cnblogs.com/itech/archive/2012/08/07/2627267.html 代码: 需要显式地定义变量且初始化.例如optionX. 如果没有定义 ...
- nginx+php-fpm 的配置下,php的错误日志
发现php 运行错误时,浏览器的网页上并没有输出php的错误日志.那php的错误日志在哪里呢? 发现在 /var/log/nginx/error.log文件中. 怎么样才能在浏览器的网页中输出php的 ...