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. 一文吃透Elasticsearch

    本文已经收录到Github仓库,该仓库包含计算机基础.Java基础.多线程.JVM.数据库.Redis.Spring.Mybatis.SpringMVC.SpringBoot.分布式.微服务.设计模式 ...

  2. 【谷粒商城】(二)SpringCloudAlibaba分布式组件

    微服务 分布式组件 注册中心:每一个微服务上线都应该注册到注册中心.这样做的好处在于方便微服务之间的相互调用,比如订单服务想要调用商品服务,就可以通过注册中心查看有哪几台主机的商品服务进行了注册,然后 ...

  3. DeepSpeed Chat: 一键式RLHF训练,让你的类ChatGPT千亿大模型提速省钱15倍

    DeepSpeed Chat: 一键式RLHF训练,让你的类ChatGPT千亿大模型提速省钱15倍 1. 概述 近日来,ChatGPT及类似模型引发了人工智能(AI)领域的一场风潮. 这场风潮对数字世 ...

  4. WebAssembly 助力云原生:APISIX 如何借助 Wasm 插件实现扩展功能?

    本文将介绍 Wasm,以及 Apache APISIX 如何实现 Wasm 功能. 作者朱欣欣,API7.ai 技术工程师 原文链接 什么是 Wasm Wasm 是 WebAssembly 的缩写.W ...

  5. k8s介绍与常用命令

    kubernetes基础与常用命令 原文地址 https://blog.csdn.net/footless_bird/article/details/125798691 官方文档 https://ku ...

  6. abp(net core)+easyui+efcore实现仓储管理系统——组织管理升级之下(六十二)

    Abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...

  7. 【Docker】镜像管理

    一.搜索镜像 1.在官方网站搜索镜像 Docker 官方镜像仓库:https://hub.docker.com/ 2.docker search 搜索镜像 Usage: docker search [ ...

  8. 【Python基础】集合的基本使用

    Python中的集合是一种无序且唯一的数据结构.集合是通过花括号{}或者set()函数来创建的. 创建集合 s = set() 声明空集合 s = {1,2,3,4,5} 声明非空集合 添加元素 s. ...

  9. 从浏览器输入域名开始分析DNS解析过程

    摘要:DNS(Domain Name System)是域名系统的英文缩写,是一种组织成域层次结构的计算机和网络服务命名系统,用于 TCP/IP 网络. 本文分享自华为云社区<DNS那些事--从浏 ...

  10. 2021-11-21:map[i][j] == 0,代表(i,j)是海洋,渡过的话代价是2, map[i][j] == 1,代表(i,j)是陆地,渡过的话代价是1, map[i][j] == 2,代表

    2021-11-21:map[i][j] == 0,代表(i,j)是海洋,渡过的话代价是2, map[i][j] == 1,代表(i,j)是陆地,渡过的话代价是1, map[i][j] == 2,代表 ...