用并查集看一下是否会围成一个环  若围成环直接输出NO   当然 当 m >= n  时必然会围成环直接输出NO

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; int f[10010]; int find(int x)
{
return f[x] == x ? x : f[x] = find(f[x]);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
if(m >= n)
{
puts("NO");
return 0;
}
else
{
for(int i = 1; i <= n; i++) f[i] = i;
for(int i = 0; i < m; i++)
{
int u,v;
scanf("%d%d",&u,&v);
int x = find(u), y = find(v);
if(x != y)
{
f[x] = y;
}
else
{
puts("NO");
return 0;
}
}
puts("YES");
}
return 0;
}

spoj 1436的更多相关文章

  1. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  2. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  3. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  4. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  5. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  6. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  7. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  8. 【SPOJ 8222】Substrings

    http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...

  9. SPOJ GSS2 Can you answer these queries II

    Time Limit: 1000MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description Being a ...

随机推荐

  1. C# 日期减法

    public class DateExample { public static void Main() { DateTime dt1 = new DateTime(2012, 7, 16); Dat ...

  2. 关于C/C++中的位运算技巧

    本篇文章讲述在学习CSAPP位运算LAB时的一些心得. 移位运算的小技巧 C/C++对于移位运算具有不同的策略,对于无符号数,左右移位为逻辑移位,也就是直接移位:对于有符号数,采用算术移位的方式,即左 ...

  3. Using OpenCV Java with Eclipse

    转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html Using Open ...

  4. 压力测试工具siege的用法

    Siege是linux下的一个web系统的压力测试工具,支持多链接,支持get和post请求,可以对web系统进行多并发下持续请求的压力测试. 安装 Siege 01 02 03 04 #wget h ...

  5. asp.net get server control id from javascript

    var WhateverValue = document.getElementById('<%= saveValue.ClientID %>').value

  6. encodeURIComponent与encodeURI的区别

    encodeURIComponent()   -->把字符串编码为 URI 组件. encodeURI()                   -->把字符串编码为 URI. var te ...

  7. 【转】 c++拷贝构造函数(深拷贝,浅拷贝)详解

     c++拷贝构造函数(深拷贝,浅拷贝)详解 2013-11-05 20:30:29 分类: C/C++ 原文地址:http://blog.chinaunix.net/uid-28977986-id-3 ...

  8. sublime 设置localhost 2

    最近sidebar用不了了,提示更新然后就自动卸载了: 研究了下其他方式实现: Sublime Text 2 Sublime Text 3 都可以使用: 菜单 --> Tools --> ...

  9. ECSHOP 商品页详情页 添加同类随机商品

    1,根目录下找到goods.php文件 找到代码  $smarty->assign('properties',          $properties['pro']);             ...

  10. ItemsControl 使用Grid布局

    ItemsControl控件经常用到,在ItemsPanel里大多是StackPanel,WrapPanel,以下项目演示如何使用Grid用于ItemsControl布局 1.先看运行效果 2.xam ...