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. python 保存文本txt格式之总结篇,ANSI,unicode,UTF-8

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4wAAAEmCAIAAACmsIlUAAAgAElEQVR4nOydezxU+f/HP49WSstKkZ

  2. PLSQL Developer 连接oracle(64)(instantclient_32)

    下载instantclient-basic-nt-11.2.0.2.0位客户端,加压后存放,如F:\instantclient_11_2 拷贝Oracle 11.2G的msvcr80.dll和tnsn ...

  3. html5获取用户当前的地理位置,即经纬度。

    $("document").ready(function(){ getMap(); }); function getMap(){ // 百度地图API功能 var map = ne ...

  4. SQL Server 锁机制 悲观锁 乐观锁 实测解析

    先引入一些概念,直接Copy其他Blogs中的,我就不单独写了. 一.为什么会有锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 1.丢失更新 A,B两个用户读同一数据并进行修改,其中 ...

  5. 关于AVALON总线动态地址对齐

    在NIOS的使用中,我们往往要用到自定义外设,然后通过AVALON交换架构和NIOSII进行通信. AVALON总线,其实是一种交换架构的协议,在自定义外设挂在AVALON总线上时,一定要注意地址对齐 ...

  6. 移动端效果之CellSwiper

    写在前面 接着之前的移动端效果讲解,刚好项目中需要使用到这一效果,去饿了么的组件库看了一下效果,发现效果和微信端的cellSwiper还是有点差别的,由于项目中又是使用的React,之前使用的Reac ...

  7. ZOJ2212 Argus 优先队列 结构体

    #include <iostream> #include <string> #include <queue> using namespace std; struct ...

  8. c#使用GDI+简单绘图(二)

    // Create the in-memory bitmap where you will draw the image. // This bitmap is 300 pixels wide and ...

  9. 面向对象(OOP)--OOP基础与this指向详解

      前  言            学过程序语言的都知道,我们的程序语言进化是从“面向机器”.到“面向过程”.再到“面向对象”一步步的发展而来.类似于汇编语言这样的面向机器的语言,随着时代的发展已经逐 ...

  10. 初学者易上手的SSH-struts2 04值栈与ognl表达式

    什么是值栈?struts2里面本身提供的一种存储机制,类似于域对象,值栈,可以存值和取值.,特点:先进后出.如果将它当做一个容器的话,而这个容器有两个元素,那么最上面的元素叫做栈顶元素,也就是所说的压 ...