题目链接:

C1. Brain Network (easy)

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
  1. 4 4
    1 2
    2 3
    3 1
    4 1
output
  1. no
input
  1. 6 5
    1 2
    2 3
    3 4
    4 5
    3 6
output
  1. yes
  2.  
  3. 题意:
  4.  
  5. n个节点和m条边,判断是否是一棵树;
  6.  
  7. 思路:
  8.  
  9. bfs();
  10.  
  11. AC代码:
  1. #include <bits/stdc++.h>
  2. /*
  3. #include <vector>
  4. #include <iostream>
  5. #include <queue>
  6. #include <cmath>
  7. #include <map>
  8. #include <cstring>
  9. #include <algorithm>
  10. #include <cstdio>
  11. */
  12. using namespace std;
  13. #define For(i,j,n) for(int i=j;i<=n;i++)
  14. #define Riep(n) for(int i=1;i<=n;i++)
  15. #define Riop(n) for(int i=0;i<n;i++)
  16. #define Rjep(n) for(int j=1;j<=n;j++)
  17. #define Rjop(n) for(int j=0;j<n;j++)
  18. #define mst(ss,b) memset(ss,b,sizeof(ss));
  19. typedef long long LL;
  20. template<class T> void read(T&num) {
  21. char CH; bool F=false;
  22. for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
  23. for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
  24. F && (num=-num);
  25. }
  26. int stk[], tp;
  27. template<class T> inline void print(T p) {
  28. if(!p) { puts(""); return; }
  29. while(p) stk[++ tp] = p%, p/=;
  30. while(tp) putchar(stk[tp--] + '');
  31. putchar('\n');
  32. }
  33.  
  34. const LL mod=1e9+;
  35. const double PI=acos(-1.0);
  36. const LL inf=1e18;
  37. const int N=3e5+;
  38. const int maxn=;
  39. const double eps=1e-;
  40.  
  41. int n,m,vis[];
  42. vector<int>ve[];
  43. queue<int>qu;
  44.  
  45. void bfs()
  46. {
  47.  
  48. qu.push();
  49. vis[]=;
  50. int num=;
  51. while(!qu.empty())
  52. {
  53. int fr=qu.front();
  54. qu.pop();
  55. num++;
  56. int len=ve[fr].size();
  57. for(int i=;i<len;i++)
  58. {
  59. int y=ve[fr][i];
  60. if(!vis[y])
  61. {
  62. vis[y]=;
  63. qu.push(y);
  64. }
  65. }
  66. }
  67. if(num==n&&m==n-)cout<<"yes"<<"\n";
  68. else cout<<"no"<<"\n";
  69. }
  70.  
  71. int main()
  72. {
  73. int u,v;
  74. read(n);read(m);
  75. For(i,,m)
  76. {
  77. read(u);read(v);
  78. ve[u].push_back(v);
  79. ve[v].push_back(u);
  80. }
  81. bfs();
  82. return ;
  83. }

codeforces 690C1 C1. Brain Network (easy)(水题)的更多相关文章

  1. codeforces 707A A. Brain's Photos(水题)

    题目链接: A. Brain's Photos 题意: 问是黑白还是彩色; 思路: 没有思路: AC代码: #include <iostream> #include <cstdio& ...

  2. 【Codeforces 707A】Brain's Photos 水题

    黑白灰都是#Black&White #include <cstdio> int n,m; int main() { scanf("%d%d",&n,&a ...

  3. Brain Network (easy)(并查集水题)

    G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  4. Brain Network (easy)

    Brain Network (easy) One particularly well-known fact about zombies is that they move and think terr ...

  5. CodeForces 690C1 Brain Network (easy) (水题,判断树)

    题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...

  6. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  7. codeforces 690C2 C2. Brain Network (medium)(bfs+树的直径)

    题目链接: C2. Brain Network (medium) time limit per test 2 seconds memory limit per test 256 megabytes i ...

  8. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  9. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

随机推荐

  1. Spring Task Schedule 及多线程

    http://spring.io/blog/2010/01/05/task-scheduling-simplifications-in-spring-3-0/‘ http://ekramalikazi ...

  2. UTF-8 编码的文件在处理时要注意 BOM 文件头问题

    最近在给项目团队开发一个基于 Java 的通用的 XML 分析器时,设计了一个方法,能够读取现成的 XML 文件进行分析处理,当然 XML 都是采用 UTF-8 进行编码的.但是在用 UltraEdi ...

  3. 词法分析器 /c++实现

    #include<iostream> #include<string> #include<vector> #include<map> #include& ...

  4. 深入探究Java中hashCode()和equals()的关系

    目录 一.基础:hashCode() 和 equals() 简介 equals() hashCode() 二. 漫谈:初识 hashCode() 与 equals() 之间的关系 三. 解密:深入理解 ...

  5. Ubuntu下使用UFW配置防火墙(简化iptables的操作)

    UFW全称为Uncomplicated Firewall,是Ubuntu系统上配置iptables防火墙的工具.UFW提供一个非常友好的命令用于创建基于IPV4,IPV6的防火墙规则. 但是,UFW是 ...

  6. BZOJ 2809 APIO 2012 dispatching 平衡树启示式合并

    题目大意:给出一棵树,每个节点有两个值,各自是这个忍者的薪水和忍者的领导力.客户的惬意程度是这个点的领导力乘可以取得人数.前提是取的人的薪水总和不超过总的钱数. 思路:仅仅能在子树中操作.贪心的想,我 ...

  7. HDU1114 Piggy-Bank 【全然背包】

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  8. 【转载】5种网络IO模型

    同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问题其实不同的人给出 ...

  9. VirtualBox 虚拟Ubuntu系统与主机互ping

    互ping的前提是主机和虚拟机的ip地址在同一波段[eg:主机为:192.168.1.10虚拟Linux:192.168.1.11] 1.设置主机ip:                         ...

  10. 不能实现RadioButton默认选择

    当用RadioButton时,希望在程序运行的时候默认一个选项: CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1); //CheckRadioBut ...