Circle

  Memory Limit: 32768KB   64bit IO Format: %lld & %llu

Status

Description

Your task is so easy. I will give you an undirected graph, and you just need to tell me whether the graph is just a circle. A cycle is three or more nodes V1, V2, V3, ... Vk, such that there are edges between V1 and V2, V2 and V3, ... Vk and V1, with no other extra edges. The graph will not contain self-loop. Furthermore, there is at most one edge between two nodes.

Input

There are multiple cases (no more than 10).

The first line contains two integers n and m, which indicate the number of nodes and the number of edges (1 < n < 10, 1 <= m < 20).

Following are m lines, each contains two integers x and y (1 <= x, y <= n, x != y), which means there is an edge between node x and node y.

There is a blank line between cases.

Output

If the graph is just a circle, output "YES", otherwise output "NO".

Sample Input

3 3
1 2
2 3
1 3 4 4
1 2
2 3
3 1
1 4

Sample Output

YES
NO

Hint

/*
判环,每个点给出的时候,会调用两次,每个点的祖先都是一个
*/
#include<bits/stdc++.h>
#define N 50
using namespace std;
int bin[N];
int visit[N];
int n,m;
int findx(int x)
{
while(x!=bin[x])
x=bin[x];
return x;
}
void built(int x,int y)
{
int fx=findx(x);
int fy=findx(y);
if(fx!=fy)
bin[fx]=fy;
}
bool ok()
{
for(int i=;i<=n;i++)
{
//cout<<i<<"="<<visit[i]<<endl;
if(visit[i]!=)
return false;
}
for(int i=;i<=n;i++)
{
if(findx(i)!=findx())
return false;
}
return true;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(visit,,sizeof visit);
for(int i=;i<n;i++)
bin[i]=i;
int x,y;
while(m--)
{
scanf("%d%d",&x,&y);
visit[x]++;
visit[y]++;
built(x,y);
}
if(ok())
puts("YES");
else
puts("NO");
}
}

Source

The 10th Zhejiang University Programming Contest
 

Circle的更多相关文章

  1. [翻译svg教程]svg中的circle元素

    svg中的<circle> 元素,是用来绘制圆形的,例如 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink= ...

  2. 设计一个程序,程序中有三个类,Triangle,Lader,Circle。

    //此程序写出三个类,triangle,lader,circle:其中triangle类具有类型为double的a,b,c边以及周长,面积属性, //具有周长,面积以及修改三边的功能,还有判断能否构成 ...

  3. c++作业:Circle

    Circle Github链接

  4. Modified Least Square Method and Ransan Method to Fit Circle from Data

    In OpenCv, it only provide the function fitEllipse to fit Ellipse, but doesn't provide function to f ...

  5. [javascript svg fill stroke stroke-width circle 属性讲解] svg fill stroke stroke-width circle 属性 绘制圆形及引入方式讲解

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  6. (1)编写一个接口ShapePara,要求: 接口中的方法: int getArea():获得图形的面积。int getCircumference():获得图形的周长 (2)编写一个圆类Circle,要求:圆类Circle实现接口ShapePara。 该类包含有成员变量: radius:public 修饰的double类型radius,表示圆的半径。 x:private修饰的double型变量x,

    package com.hanqi.test; //创建接口 public interface ShapePara { //获取面积的方法 double getArea(); //获取周长的方法 do ...

  7. 东大oj-1591 Circle of friends

    题目描述 Nowadays, "Circle of Friends" is a very popular social networking platform in WeChat. ...

  8. svg学习(四)circle

    <circle> 标签 < <?xml version="1.0" standalone="no"?> <!DOCTYPE ...

  9. 后缀数组 --- WOj 1564 Problem 1564 - A - Circle

    Problem 1564 - A - Circle Problem's Link:   http://acm.whu.edu.cn/land/problem/detail?problem_id=156 ...

  10. iOS 中使用Block时需要注意的retain circle

    现在在ios中,block是越来越多了.自己在类中定义block对象时,需要注意block对象的使用方法,防止产生retain circle,导致内存泄露. 现在分析一下产生retain circle ...

随机推荐

  1. A glimpse of Support Vector Machine

    支持向量机(support vector machine, 以下简称svm)是机器学习里的重要方法,特别适用于中小型样本.非线性.高维的分类和回归问题.本篇希望在正篇提供一个svm的简明阐述,附录则提 ...

  2. wget下载整个网站

    wget下载整个网站wget下载整个网站可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps , -r 表示递归下载,会下载所有的链接,不过要注意的 ...

  3. 都是Javascript的作用域惹得祸

    案件重现 今天有位然之OA 系统的定制开发用户咨询了个问题,他想在新加的功能模块的操作面板中,实现用户点击删除按钮时提示友好提醒,如下: 问题很简单,虽然他自己最终达到目的效果了,但不知道起初问题出在 ...

  4. 第5章 不要让线程成为脱缰的野马(Keeping your Threads on Leash) ---干净的终止一个线程

    干净的终止一个线程  我曾经在第2章产生一个后台线程,用以输出一张屏幕外的 bitmap 图.我们必须解决的一个最复杂的问题就是,如果用户企图结束程序,而这张bitmap 图尚未完成,怎么办?第2章的 ...

  5. 2008-2009 ACM-ICPC, NEERC, Southern Subregional ContestF

    Problem F. Text Editor Input file: stdin Output file: stdout Time limit: 1 second Memory limit: 64 m ...

  6. PHP,Mysql根据经纬度计算距离并排序

    网上给出的计算公式是这样的: Lng1表示A点纬度和经度,Lat2 Lng2 表示B点纬度和经度 a = Lat1 – Lat2为两点纬度之差 b = Lng1 -Lng2 为两点经度之差 6378. ...

  7. SqlServer批量备份多个数据库且删除3天前的备份

    /******************************************* * 批量备份数据库且删除3天前的备份 ************************************ ...

  8. eNSP关闭保存文件的提示信息

    总是提示如下信息: Oct 12 2017 23:49:24-08:00 Huawei DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25.191.3. ...

  9. d01

    基础 <head>   <meta http-equiv="Content-Type" content="text/html; charset=utf- ...

  10. ABAP 选择屏幕创建标签页

    *&---------------------------------------------------------------------* *& Report ZTEST_TAB ...