G - Brain Network (easy)

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

CodeForces 690C1

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

  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.

Sample Input

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

//并查集水题,第一行 n , m 是点,和边个数,然后 m 边的描述,问是否都连通了且没有多余的边

 #include<stdio.h>
int f[];
int find(int x)
{
if (f[x]!=x)
f[x]=find(f[x]);
return f[x];
}
int main()
{
int n,m;
while (scanf("%d%d",&n,&m)!=EOF)
{
int i,j;
for (i=;i<=n;i++)
f[i]=i; int a,b,temp;
scanf("%d%d",&a,&b);
temp=a;
f[a]=f[b];
int ok=;
for (i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
int head_a=find(a);
int head_b=find(b);
if (head_a!=head_b)
f[head_a]=f[head_b];
else
ok=;
}
for (i=;i<=n;i++)
{
if (ok==) break;
if (find(i)!=find(temp))
{
ok=;
break;
}
}
if (ok)
printf("yes\n");
else
printf("no\n");
}
return ;
}

Brain Network (easy)(并查集水题)的更多相关文章

  1. 【PAT-并查集-水题】L2-007-家庭房产

    L2-007. 家庭房产 给定每个人的家庭成员和其自己名下的房产,请你统计出每个家庭的人口数.人均房产面积及房产套数. 输入格式: 输入第一行给出一个正整数N(<=1000),随后N行,每行按下 ...

  2. poj2524(并查集水题)

    题目链接:http://poj.org/problem?id=2524 题目大意:学校共有n个同学,告诉你m对同学信仰同一宗教,问这个学校学生信仰宗教的数目最多为多少. 例: Sample Input ...

  3. POJ2524并查集水题

    Description There are so many different religions in the world today that it is difficult to keep tr ...

  4. HDU1863(Kruskal+并查集水题)

    https://cn.vjudge.net/problem/HDU-1863 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可). ...

  5. PAT题解-1118. Birds in Forest (25)-(并查集模板题)

    如题... #include <iostream> #include <cstdio> #include <algorithm> #include <stri ...

  6. codeforces 690C1 C1. Brain Network (easy)(水题)

    题目链接: C1. Brain Network (easy) time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  7. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  8. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  9. POJ 2236:Wireless Network(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 36363   Accepted: 150 ...

随机推荐

  1. C++中的类所占内存空间+继承中的成员访问控制

    C++学习之继承中的成员访问控制 C++中的类所占内存空间总结

  2. ElasticSearch5.5.2常用命令

    1.启动 转到elasticsearch-5.5.2\bin目录: 打开命令行输入:elasticsearch 2.ELasticsearch集群已经启动并且正常运行 curl http://127. ...

  3. 机器学习第2课:单变量线性回归(Linear Regression with One Variable)

    2.1  模型表示 之前的房屋交易问题为例,假使我们回归问题的训练集(Training Set)如下表所示: 我们将要用来描述这个回归问题的标记如下: m                代表训练集中实 ...

  4. Linux学习之二十-Linux文件系统

    Linux文件系统 文件系统的定义 文件系统是操作系统的必备软件,文件系统是对一个存储设备上的数据(block)和元数据(inode)进行组织的一种机制.文件系统可以帮助用户管理磁盘空间,进行文件的快 ...

  5. ECSHOP站内页面跳转,避免死链

    2.x版本域名重定向: # For ISAPI_Rewrite 2.x RewriteCond Host: ^steveluo\.name$ RewriteRule (.*) http\://www\ ...

  6. MonoBehaviour.FixedUpdate 固定更新

    function FixedUpdate () : void Description描述 This function is called every fixed framerate frame, if ...

  7. tomcat使用redis存储共享session

    在tomcat集群环境下实现session共享有几种解决方式,这里介绍一种简单的方案. 使用redis对session进行存储,配置比較简单.webserver是tomcat6 1.下载jar包: c ...

  8. scrapy框架爬取豆瓣读书(1)

    1.scrapy框架 Scrapy,Python开发的一个快速.高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据.Scrapy用途广泛,可以用于数据挖掘.监测和自动化测试 ...

  9. centos7 重启网卡报错

    systemctl restart network 时候报错: rtnetlink answers file exists 是network和NetworkManager冲突了 一般建议直接 syst ...

  10. 搭建Squid反向代理服务器

    好吧,更新个文章,有段时间没写技术博文了.今天就说说squid反向代理这个服务,当然,这是在Linux下配置完成的.说自己没偏见似乎不可能 了.大概是相对喜欢Linux而已.但我从不否认Windows ...