链接:http://codeforces.com/problemset/problem/103/B
题意:给定一个图,判断该图是否由若干棵树的树根构成一个环
题解:先并查集判连通,并且满足n=m
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
using namespace std;int n, m;
int fa[110];
vector<int> G[110];int Find(int x){return x == fa[x]?x:fa[x] = Find(fa[x]);
}void join(int x, int y){int root1 = Find(x);int root2 = Find(y);if(root1!=root2){fa[root1] = root2;}
}int main(){cin>>n>>m;for(int i = 1; i<=n; i++) fa[i] = i;for(int i =0 ;i<m; i++){int u, v;cin>>u>>v;G[u].push_back(v);G[v].push_back(u);join(u, v);}/*for(int i = 1; i<=n; i++){cout<<i<<" "<<fa[i]<<endl;}*/bool flag = true;for(int i = 1; i<=n; i++){if(Find(i)!=Find(1)){flag = false;}}if(n!=m) flag = false;if(flag == false) cout<<"NO"<<endl;else cout<<"FHTAGN!"<<endl;return 0;
}

codeforces-103B Cthulhu相关推荐

  1. CodeForces 103B Cthulhu

    http://codeforces.com/problemset/problem/103/B 找环,一个环 #include<bits/stdc++.h> using namespace ...

  2. Codeforces 103B. Cthulhu 并查集运用

    题目链接: 题面: ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to ...

  3. Codeforces 103B - Cthulhu(并查集 找环和块)

    传送门:https://codeforces.com/problemset/problem/103/B 题意: 给一个n个结点,m条边的无向图 判断给定图是否满足以下条件: 能被表示为有3个及以上的有 ...

  4. Codeforces 103B Cthulhu

    题意: 给你n个点m条边的无向图(无重边和自环),问你是否存在一个简单的环且环上的点都是某棵树的树根. 思路: 注意这句话:an undirected graph that can be repres ...

  5. A - Cthulhu CodeForces - 103B (并查集)

    -Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for th ...

  6. Round 2 A - Cthulhu CodeForces - 103B -图同构,DFS

    题目链接: http://codeforces.com/problemset/problem/103/B 大意: 判断图的形状是否为一个章鱼型(?) 由几棵树构成,树的根节点围成一个环. 思路: 只需 ...

  7. Codeforces 104C Cthulhu dfs暴力 || 点双连通缩点

    题目链接:点击打开链接 题意: 给定n个点m条边的无向图 问图中是否存在 有且仅有一个简单环和一些树,且这些树的root都在这个简单环上. 瞎写了个点双..== #include <stdio. ...

  8. 【CodeForces】CF103B Cthulhu

    题目地址: https://www.luogu.com.cn/problem/CF103B 题面翻译: 很久很久以前的一天,一位美男子来到海边,海上狂风大作.美男子希望在海中找到美人鱼,但是很不幸他只 ...

  9. codeforces Cthulhu 简单图论

    题意:给定一个点集,和边集,问这个它的结构是不是像妖怪. 做法:水,只要DFS判断是否只有一个联通分量,然后再判断N=M即可 #include <iostream> #include &l ...

  10. CodeForces:103(div1)104(div2)

    文章目录 前言 CF104A Blackjack Description\text{Description}Description Solution\text{Solution}Solution Co ...

最新文章

  1. 允许活动内容如脚本和activex控件
  2. php进程学习(一)
  3. P1199 三国游戏
  4. 前端学习(2165):vuecli3创建项目和目录结构
  5. ubuntu 16.04下git的安装与使用
  6. 理论+实践,带你掌握动态规划法
  7. 《Java 8 in Action》Chapter 12:新的日期和时间API
  8. 拼接Sql语句的写法
  9. 第十四章 深度确定性策略梯度(Deep Deterministic Policy Gradient Algorithms,DDPG)-强化学习理论学习与代码实现(强化学习导论第二版)
  10. [导入]+ADO.NET读书笔记系列 一+
  11. 简易语音助手—python
  12. 苹果安卓最新看片神器各种实用功能,帮你一年省下上千块!
  13. 住宅内部通信系统市场现状研究分析与发展前景预测报告
  14. 如何正确的将拼多多的买家晒图采集并保存
  15. 柏拉图式爱情 (精神爱情)
  16. c语言choice的用法,名词choice的用法与搭配
  17. FinalShell连接超时解决方法
  18. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的三种解决方式
  19. UE4中的玩家类UPlayer、ULocalPlayer 和 UNetConnection
  20. isEmpty与null的区别

热门文章

  1. pythonista3中文设置教程_Pythonista中文文档:使用Pythonista
  2. 百度文字转语音免费接口使用实例
  3. 条码打印实现预览功能(winform)
  4. iphone,ipad分辨率大全
  5. (keil4 51单片机)D:\uVision\C51\Inc\reg52.h(13): error C231: ‘P0‘: redefinition
  6. 联通研究院注重自主研发能力提升, 3人荣获CKA认证
  7. 送口红分不清色号,送花认不全品种?机器学习一键搞定!
  8. C++ sizeof(struct)计算结构体大小
  9. Loading 用户体验 - 加载时避免闪烁
  10. oracle怎么查询关键字,9、oracle表查询关键字