Description

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 nbrains (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:

  1. It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains).
  2. 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.

Input

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 ab it connects (1 ≤ a, b ≤ na ≠ b).

Output

The output consists of one line, containing either yes or no depending on whether the nervous system is valid.

Examples
input
4 4
1 2
2 3
3 1
4 1
output
no
input
6 5
1 2
2 3
3 4
4 5
3 6
output
yes
并查集判断环~
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
//#include<map>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
using namespace std;
const double pi = acos(-1.);
#define maxn 100005
int fa[maxn];
bool ff[maxn];
int findd( int x )
{
int k, j, r;
r = x;
while(r != fa[r]) //查找跟节点
r = fa[r]; //找到跟节点,用r记录下
k = x;
while(k != r) //非递归路径压缩操作
{
j = fa[k]; //用j暂存parent[k]的父节点
fa[k] = r; //parent[x]指向跟节点
k = j; //k移到父节点
}
return r; //返回根节点的值
}
int main()
{
int u,v,x,y,flag = 1;
memset(ff, false, sizeof(ff));
int k = 0;
int n,m;
cin>>n>>m;
for(int i = 1; i <=n; i++)
{
fa[i]=i;
}
for(int j=1;j<=m;j++)
{
cin>>u>>v;
x = findd(u), y = findd(v);
if(x!=y)
fa[x]=y;
else
flag=0;
}
for(int i=1;i<=n;i++)
{
if(fa[i]==i)
{
k++;
}
}
if(flag&&k<=1)
{
puts("yes");
}
else
{
puts("no");
}
return 0;
}

  

Helvetic Coding Contest 2016 online mirror C1的更多相关文章

  1. CF 690C3. Brain Network (hard) from Helvetic Coding Contest 2016 online mirror (teams, unrated)

    题目描述 Brain Network (hard) 这个问题就是给出一个不断加边的树,保证每一次加边之后都只有一个连通块(每一次连的点都是之前出现过的),问每一次加边之后树的直径. 算法 每一次增加一 ...

  2. Helvetic Coding Contest 2016 online mirror A1

    Description Tonight is brain dinner night and all zombies will gather together to scarf down some de ...

  3. Helvetic Coding Contest 2016 online mirror F1

    Description Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure ...

  4. Helvetic Coding Contest 2016 online mirror B1

    Description The zombies are gathering in their secret lair! Heidi will strike hard to destroy them o ...

  5. Helvetic Coding Contest 2016 online mirror C2

    Description Further research on zombie thought processes yielded interesting results. As we know fro ...

  6. Helvetic Coding Contest 2016 online mirror D1

    Description "The zombies are lurking outside. Waiting. Moaning. And when they come..." &qu ...

  7. Helvetic Coding Contest 2019 online mirror (teams allowed, unrated)

    http://codeforces.com/contest/1184 A1 找一对整数,使x^x+2xy+x+1=r 变换成一个分式,保证整除 #include<iostream> #in ...

  8. [Helvetic Coding Contest 2017 online mirror]

    来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...

  9. 【Codeforces】Helvetic Coding Contest 2017 online mirror比赛记

    第一次打ACM赛制的团队赛,感觉还行: 好吧主要是切水题: 开场先挑着做五道EASY,他们分给我D题,woc什么玩意,还泊松分布,我连题都读不懂好吗! 果断弃掉了,换了M和J,然后切掉了,看N题: l ...

随机推荐

  1. C/C++面试题总结(1)

    首先说一下,这些东西,有的是必须掌握的,有的是面试时你讲出来就是闪光点.自己把握.把握不好的都搞懂.实在不行背下来. 由于时间关系,总结的比较随意,有的就直接贴链接了,希望理解一下. 第一篇:基础(必 ...

  2. 数据schemaAvro简介

    文章结束给大家来个程序员笑话:[M] 最近在研究Thrift和Avro以及它们的区分,通过各种渠道搜集资料,现整顿出有关Avro的一些资料,方便当前参考. 一.弁言 1. 简介 Avro是Hadoop ...

  3. linux shell查询

    查看当前版本可用的shell cat /etc/shells 查看当前使用的shell echo $0 查看当前用户默认使用的shell echo $SHELL

  4. ES6学习之Reflect

    Reflect对象与Proxy对象一样,也是 ES6 为了操作对象而提供的新 API Reflect设计目的: 将Object对象的一些明显属于语言内部的方法(比如Object.definePrope ...

  5. java处理中日文字符串的乱码问题

    ——杂言:前段时间在处理音频预览问题,详见关于audiojs的研究.期间,将远端的音频下载并缓存在本地过程中,涉及到java.io.*的几个操作,发生一些乱码问题. 我以前的处理是将本地的编码转换为U ...

  6. day18-事务与连接池 6.事务隔离级别与解决问题

    开两个cmd窗口,相当于两个事务. read-uncommitted这种级别是解决不了任何问题的,它什么情况都能出现.刚才演示了脏读,再演示就出现了不可重复读. read-committed隔离级别能 ...

  7. [51nod1247]可能的路径(思维题)

    题意:给定(a,b),(x,y)  ,(a,b)可以通向(a-b,b) (a+b,b) (a,a+b) (a,a-b) 求能否到达(x,y) 解题关键:类似于更相减损,变换过程中gcd是一样的. #i ...

  8. Learning Python 010 函数 1

    Python 函数 1 调用函数 举个例子 多于Python内部的函数,你可以在Python的交互式终端中使用help()函数来查看函数的使用方法.比如:abs()函数,如果你不知道如何使用它,你可以 ...

  9. Jmeter JDBC Request的sql语句不支持;号

    Jmeter JDBC Request的sql语句不支持:号,如果要批量插入数据,则需要使用以下方式 INSERT INTO bank_info( `id`, `bank_code`, `bank_n ...

  10. JsonPath的用法

    有时候需要从json里面提取相关数据,必须得用到如何提取信息的知识,下面来写一下 语法格式 JsonPath 描述 $ 根节点 @ 当前节点 .or[] 子节点 .. 选择所有符合条件的节点 * 所有 ...