CF103B Cthulhu

点击查看题目

点击查看思路

如果 \(n < m\),那么会形成多个环。

如果 \(n > m\),那么不会形成环。

只有 \(n = m\) 时会形成环,

那么使用并查集看环的数量是否等于 \(1\),即可。

点击查看代码
#include <bits/stdc++.h>

using namespace std;

const int N = 110;

int n, m;
int fa[N]; int find(int x) {
if (x == fa[x]) return x;
return fa[x] = find(fa[x]);
} int merge(int x, int y) {
int fx = find(x), fy = find(y);
if (fx == fy) return fx;
fa[fx] = fy;
return fy;
} int main() {
#ifdef DEBUG
freopen("D:/Exercise/Test.in", "r", stdin);
clock_t st, ed;
cout << "===================START===================" << endl;
st = clock();
#endif cin >> n >> m;
if (n != m) {
cout << "NO\n";
return 0;
}
for (int i = 1; i <= n; i++) fa[i] = i;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
merge(x, y);
} for (int i = 2; i <= n; i++) {
if (find(i) != find(i - 1)) {
cout << "NO\n";
return 0;
}
}
cout << "FHTAGN!\n";
#ifdef DEBUG
ed = clock();
cout << "====================END====================" << endl;
cout << "Time:" << (ed - st) * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
return 0;
}

CF103B Cthulhu题解的更多相关文章

  1. codeforce 103B Cthulhu

    B. Cthulhu time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  10. CF100965C题解..

    求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...

随机推荐

  1. fio性能测试-环境搭建,功能介绍,测试讲解

    fio性能测试-环境搭建,功能介绍,测试讲解 Fio介绍:FIO(Flexible I/O Tester)是一个用于测试磁盘.文件系统.块设备和网络设备性能的工具.它可以模拟不同类型的I/O负载,包括 ...

  2. JUC(八)ThreadLocal

    ThreadLocal 简介 ThreadLocal提供局部线程变量,这个变量与普通的变量不同,每个线程在访问ThreadLocal实例的时候,(通过get或者set方法)都有自己的.独立初始化变量副 ...

  3. Redis分布式锁这样用,有坑?

    背景 在微服务项目中,大家都会去使用到分布式锁,一般也是使用Redis去实现,使用RedisTemplate.Redisson.RedisLockRegistry都行,公司的项目中,使用的是Redis ...

  4. Java学习笔记08

    1. static关键字 ​ static可以用来修饰的成员变量和成员方法,被static修饰的成员是属于类的是放在静态区中,没有static修饰的成员变量和方法则是属于对象的. 1.1 静态变量 ​ ...

  5. 【深度思考】聊聊JDK动态代理原理

    1. 示例 首先,定义一个接口: public interface Staff { void work(); } 然后,新增一个类并实现上面的接口: public class Coder implem ...

  6. 【python基础】定时任务框架APScheduler

    1. 基础概念 APScheduler是python中较为简洁直观的定时任务框架,提供了基于固定日期.时间间隔.crontab表达式三种任务类型,并且可以持久化任务(如:将定时任务保存到mysql中) ...

  7. 统计计算——Bootstrap总结整理

    Bootstrapping Boostrap 有放回的重抽样. 符号定义: 重复抽样的bootstrap \(F^*\) 观测到的样本\(\hat F\),是一个经验分布 真实分布\(F\) Eg. ...

  8. shell基本命令与参数

    1:一行可以有多个命令,用";"分开 如: cd ..; ls -l 2:先项用"-"开始,多个连接可连在一起,如:ls -lh, 3:"--&quo ...

  9. [图像处理]仿射变换(Affine Transformation)

    文章目录 仿射变换(Affine Transformation) 平移变换 Translation 缩放变换(Scale) 剪切变换(Shear) 旋转变换(Rotation) 组合 仿射变换(Aff ...

  10. Stream方法的介绍

    文章目录 前言 Lambda表达式 格式 函数式接口 Stream的方法介绍 forEach filter collect count sum limit 和skip groupingBy reduc ...