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. 关于ElasticSearch默认窗口结果集参数max_result_window修改

    在Linux服务器中执行如下命令 curl -XPUT http://192.168.46.163:9200/t_order/_settings -d '{ "index" : { ...

  2. asp.net敏感词过滤

    敏感词过滤是一个能够让用户发表评论的网站的一个很重要的功能(你懂的~) 下面开始全套流程: 1.需要有一套比较完整的词库,由于我的词库很少所以就不贴上来了,网上找找应该很多 2.设计一个可以将词库导入 ...

  3. 2017.6.27 jdbc基本使用

    参考来自:http://www.runoob.com/w3cnote/jdbc-use-guide.html 1.jdbc的执行流程 JDBC API 允许用户访问任何形式的表格数据,尤其是存储在关系 ...

  4. webstrom 中 plugins error 设置里 Languages & Frameworks里面没有JavaScript?

    不知道哪里不对 js突然不支持高亮 于是在设置里面找language & frameworks里面的JavaScript 选项 但是竟然没有JavaScript选项. 还有plugins er ...

  5. iOS开发--Mac下server搭建

    前言 对于Mac电脑的认识.我一直停留在装B神器的意识上.就在前两天我彻底改变了庸俗的看法,当时忙着写毕业设计.苦于iOS开发没有server, 数据都是从网上抓取或本地plist文件,感觉不够高大上 ...

  6. J2EE环境安装配置

    在下载,安装前先说下以下几个概念JDK,SDK,JRE,JVM ◆JDK Java Develop Kit (Java 开发包) ◆SDK Software Develop kit, 曾经JDK叫做J ...

  7. jm解决乱码问题-参数化-数据库操作-文件上传下载

    jm解决乱码问题-参数化-数据库操作-文件上传下载 如果JM出果运行结果是乱码(解决中文BODY乱码的问题) 找到JM的安装路径,例如:C:\apache-jmeter-3.1\bin 用UE打开jm ...

  8. 工作总结 @Html.EditorFor @Html.TextBoxFor 表达式树 绑定显示日期格式数据

    页面显示 不出来 没有 这个input ............. 换成 @Html.TextBoxFor input 出来了 这是 为什么呢 ? 用@Html.TextBox 也可以出来 为什么 @ ...

  9. 记录:Android中StackOverflow的问题

    最近新作的项目上线,出现了一个让人抓狂的问题.在此记录一下! 现在的项目中,制作了一个界面非常复杂.整个结构是最外层一个Layout,封装了Menu键吊起的菜单,整个内容使用一个FrameLayout ...

  10. centos自动安装镜像脚本

    #!/bin/bash ######################################################################################## ...