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. Linux CentOS 6.5 64位 静默安装Oracle11g 云主机

    本例: 通过SSH远程连接云主机,上传oracle11g安装包,在centos6.5上无图形化界面静默安装oracle11g. 涉及工具及环境: 1.本地环境windows7+ssh远程连接工具xSh ...

  2. AngularJS方法 —— angular.bind

    描述: 上下文,函数以及参数动态绑定,返回值为绑定之后的函数. 其中args是可选的动态参数,self在fn中使用this调用. 使用方法: angular.bind(self,fn,args ); ...

  3. category extension

    1 category 分类,只能添加方法,添加的方法成为原来类的一部分,达到扩展类的目的,可以被子类继承 主要给没有源代码的类 添加方法,团队合作项目互不影响,不该动原有类的基础上添加方法 self ...

  4. java代码GUI简单的。。。

    总结:觉得 package com.da; import java.awt.*; //逆向思维:important //创建一个String对象的数组,然后执行读取文本,把文本每一行存入数组,它将读取 ...

  5. JAVA 1.7并发之Fork/Join框架

    在之前的博文里有说过executor框架,其实Fork/Join就是继承executor的升级版啦 executor用于创建一个线程池,但是需要手动的添加任务,如果需要将大型任务分治,显然比较麻烦 而 ...

  6. C#事件触发机制

    C#的事件触发机制,类似于c++的回调函数机制 我先简单说一下,委托和事件的实质,后期再重开一篇博文来详细说 委托:指向方法的指针,类似于C的函数指针 事件:是一个可以存放0个或多个方法指针的数据结构 ...

  7. c# 创建缩略图

    /// <summary> /// 创建缩略图 /// </summary> /// <param name="srcFileName">< ...

  8. cocos2dx之tolua++全面分析(一):tolua++工具本身

    在cocos2dx/tools/tolua++下面,有大量pkg文件,这些是按tolua++要求格式写好的.需要导出到lua中的c++类描述文件. 每当在c++类里增加了新函数需要导出时,应同步修改相 ...

  9. hdu1071

    #include <iostream> #include <stdio.h> using namespace std; int main() { int t; double x ...

  10. Citrix 未注册解决办法

    Citrix 经常出现未注册的问题 是因为DNS的解析 问题 ping DDC 的全名你会发现ping 不通 解决方案如下 首先 在 192.168.1.145(图站)上饭解析一下DDC(控制中心19 ...