Circle
| Memory Limit: 32768KB | 64bit IO Format: %lld & %llu |
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
Circle的更多相关文章
- [翻译svg教程]svg中的circle元素
svg中的<circle> 元素,是用来绘制圆形的,例如 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink= ...
- 设计一个程序,程序中有三个类,Triangle,Lader,Circle。
//此程序写出三个类,triangle,lader,circle:其中triangle类具有类型为double的a,b,c边以及周长,面积属性, //具有周长,面积以及修改三边的功能,还有判断能否构成 ...
- c++作业:Circle
Circle Github链接
- 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 ...
- [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 ...
- (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 ...
- 东大oj-1591 Circle of friends
题目描述 Nowadays, "Circle of Friends" is a very popular social networking platform in WeChat. ...
- svg学习(四)circle
<circle> 标签 < <?xml version="1.0" standalone="no"?> <!DOCTYPE ...
- 后缀数组 --- WOj 1564 Problem 1564 - A - Circle
Problem 1564 - A - Circle Problem's Link: http://acm.whu.edu.cn/land/problem/detail?problem_id=156 ...
- iOS 中使用Block时需要注意的retain circle
现在在ios中,block是越来越多了.自己在类中定义block对象时,需要注意block对象的使用方法,防止产生retain circle,导致内存泄露. 现在分析一下产生retain circle ...
随机推荐
- CSS的常用属性
刚开始学习前段的我,还处于初级阶段,一些东西还是会有搞不明白的时候,还是要大家多多理解.今说就一些关于CSS的常用属性吧! 一.CSS常用选择器 CSS选择器应该说是一个非常重要的工具吧,选择器用得好 ...
- angular 自定义指令详解 Directive
在angular中,Directive,自定义指令的学习,可以更好的理解angular指令的原理,当angular的指令不能满足你的需求的时候,嘿嘿,你就可以来看看这篇文章,自定义自己的指令,可以满足 ...
- Divide Sum 比赛时竟然想不出。。。。。。。
Divide Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...
- spring框架总结(01)
1.spring是什么? sprint其实就是一个开源框架,是于2003年兴起的一个轻量级的java开发框架,是有Road Johnson创建的,简单的来说spring是一个分层的JavaSE/EE( ...
- 关于加载离线SHP文件、geodatabase文件所遇到的路径问题
正文开始之前还是先吐槽一下,一行代码DEBUG了一天不知道怎么改,终于误打误撞弄出来了(以下以shp文件为例) 对于虚拟机测试 public String getPath(){ File sdDir ...
- django ajax练习
这几天遇到了django ajax请求出错的问题,总结一下 前端js:我这里创建的是一个字典格式的数据,前端js收到字典之后也是要用字典的形式去解包后台传送过来的数据,比如我下面的写法:data['s ...
- HTML5基础知识及相关笔记
HTML5基础 1.1HTML文件的基本结构和W3C标准 1.1.1HTML简介 HTML是一种描述网页的语言,一种超文本标记的语言! 1.1.2HTML文件的基本结构 头部(head) 头部是网页的 ...
- Winform退出运行后,删除运行目录(批处理方法)
/// <summary> /// Winform程序退出删除运行目录 FormClosed调用 /// </summary> private void DeletExeFil ...
- 在sqlserver2005/2008中备份数据库,收缩日志文件
---1.先备份数据库(含日志文件) use myhis go backup database myhis to disk='d:\myhis_rzbak' go ---2.设为简单恢复模式 use ...
- C#打印机操作类
using System; using System.Collections.Generic; using System.Text; namespace MacPrinter { public cla ...